• Stars
    star
    14,972
  • Rank 1,844 (Top 0.04 %)
  • Language
    Python
  • License
    MIT License
  • Created over 5 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ“š Playground and cheatsheet for learning Python. Collection of Python scripts that are split by topics and contain code examples with explanations.

Playground and Cheatsheet for Learning Python

๐Ÿ‡บ๐Ÿ‡ฆ UKRAINE IS BEING ATTACKED BY RUSSIAN ARMY. CIVILIANS ARE GETTING KILLED. RESIDENTIAL AREAS ARE GETTING BOMBED.


Build Status

This is a collection of Python scripts that are split by topics and contain code examples with explanations, different use cases and links to further readings.

Read this in: Portuguรชs, Espaรฑol, Traditional Chinese.

It is a playground because you may change or add the code to see how it works and test it out using assertions. It also allows you to lint the code you've wrote and check if it fits to Python code style guide. Altogether it might make your learning process to be more interactive and it might help you to keep code quality pretty high from very beginning.

It is a cheatsheet because you may get back to these code examples once you want to recap the syntax of standard Python statements and constructions. Also because the code is full of assertions you'll be able to see expected functions/statements output right away without launching them.

You might also be interested in ๐Ÿค– Interactive Machine Learning Experiments

How to Use This Repository

Each Python script in this repository has the following structure:

"""Lists  <--- Name of the topic here

# @see: https://www.learnpython.org/en/Lists  <-- Link to further readings goes here

Here might go more detailed explanation of the current topic (i.e. general info about Lists).
"""


def test_list_type():
    """Explanation of sub-topic goes here.
    
    Each file contains test functions that illustrate sub-topics (i.e. lists type, lists methods).
    """
    
    # Here is an example of how to build a list.  <-- Comments here explain the action
    squares = [1, 4, 9, 16, 25]
    
    # Lists can be indexed and sliced. 
    # Indexing returns the item.
    assert squares[0] == 1  # <-- Assertions here illustrate the result.
    # Slicing returns a new list.
    assert squares[-3:] == [9, 16, 25]  # <-- Assertions here illustrate the result.

So normally you might want to do the following:

  • Find the topic you want to learn or recap.
  • Read comments and/or documentation that is linked in each script's docstring (as in example above).
  • Look at code examples and assertions to see usage examples and expected output.
  • Change code or add new assertions to see how things work.
  • Run tests and lint the code to see if it work and is written correctly.

Table of Contents

  1. Getting Started
  2. Operators
  3. Data Types
  4. Control Flow
  5. Functions
  6. Classes
  7. Modules
  8. Errors and Exceptions
  9. Files
  10. Additions
  11. Brief Tour of the Standard Libraries
  12. User input

Prerequisites

Installing Python

Make sure that you have Python3 installed on your machine.

You might want to use venv standard Python library to create virtual environments and have Python, pip and all dependent packages to be installed and served from the local project directory to avoid messing with system wide packages and their versions.

Depending on your installation you might have access to Python3 interpreter either by running python or python3. The same goes for pip package manager - it may be accessible either by running pip or pip3.

You may check your Python version by running:

python --version

Note that in this repository whenever you see python it will be assumed that it is Python 3.

Installing dependencies

Install all dependencies that are required for the project by running:

pip install -r requirements.txt

Testing the Code

Tests are made using pytest framework.

You may add new tests for yourself by adding files and functions with test_ prefix (i.e. test_topic.py with def test_sub_topic() function inside).

To run all the tests please execute the following command from the project root folder:

pytest

To run specific tests please execute:

pytest ./path/to/the/test_file.py

Linting the Code

Linting is done using pylint and flake8 libraries.

PyLint

To check if the code is written with respect to PEP 8 style guide please run:

pylint ./src/

In case if linter will detect error (i.e. missing-docstring) you may want to read more about specific error by running:

pylint --help-msg=missing-docstring

More about PyLint

Flake8

To check if the code is written with respect to PEP 8 style guide please run:

flake8 ./src

Or if you want to have more detailed output you may run:

flake8 ./src --statistics --show-source --count

More about Flake8

Author

More Repositories

1

javascript-algorithms

๐Ÿ“ Algorithms and data structures implemented in JavaScript with explanations and links to further readings
JavaScript
173,558
star
2

homemade-machine-learning

๐Ÿค– Python examples of popular machine learning algorithms with interactive Jupyter demos and math being explained
Jupyter Notebook
21,617
star
3

state-of-the-art-shitcode

๐Ÿ’ฉState-of-the-art shitcode principles your project should follow to call it a proper shitcode
4,789
star
4

nano-neuron

๐Ÿค– NanoNeuron is 7 simple JavaScript functions that will give you a feeling of how machines can actually "learn"
JavaScript
2,192
star
5

promote-your-next-startup

๐Ÿš€ Free resources you may use to promote your next startup
2,000
star
6

js-image-carver

๐ŸŒ… Content-aware image resizer and object remover based on Seam Carving algorithm
TypeScript
1,504
star
7

machine-learning-experiments

๐Ÿค– Interactive Machine Learning experiments: ๐Ÿ‹๏ธmodels training + ๐ŸŽจmodels demo
Jupyter Notebook
1,461
star
8

machine-learning-octave

๐Ÿค– MatLab/Octave examples of popular machine learning algorithms with code examples and mathematics being explained
MATLAB
796
star
9

self-parking-car-evolution

๐Ÿงฌ Training the car to do self-parking using a genetic algorithm
TypeScript
688
star
10

use-position

๐ŸŒ React hook usePosition() for fetching and following a browser geolocation
JavaScript
298
star
11

covid-19

๐Ÿ“ˆ Coronavirus (COVID-19) dashboard to show the dynamics of ะกoronavirus distribution per country
JavaScript
265
star
12

nodejs-master-class

๐Ÿ›  This repository contains the homework assignment for Node.js Master Class that is focused on building a RESTful API, web app GUI, and a CLI in plain Node JS with no NPM or 3rd-party libraries
JavaScript
235
star
13

angular-library-seed

๐ŸŒพ Seed project for Angular libraries that are AOT/JIT compatible and that use external SCSS-styles and HTML-templates
TypeScript
203
star
14

okso-app

โœ๐Ÿป The drawing app to express, grasp, and organize your thoughts and ideas. Draw to explain. Draw to grasp.
198
star
15

links-detector

๐Ÿ“– ๐Ÿ‘†๐Ÿป Links Detector makes printed links clickable via your smartphone camera. No need to type a link in, just scan and click on it.
TypeScript
184
star
16

trekhleb.github.io

๐Ÿงฌ My personal website with a list of my projects that help people learn and blog posts about life, web-development, and machine-learning.
TypeScript
176
star
17

hello-docker

๐Ÿณ Example Docker project that is used as illustration for automated continuous delivery flow with DockerCloud and DigitalOcean
Python
48
star
18

micrograd-ts

๐Ÿค– A TypeScript version of karpathy/micrograd โ€” a tiny scalar-valued autograd engine and a neural net on top of it
TypeScript
42
star
19

giphygram

๐Ÿ”Ž Experimental React application for searching GIF images on GIPHY
JavaScript
24
star
20

vscode-search-tree

๐Ÿ”Ž (Draft!) VSCode extension to show the search results in a tree view
TypeScript
21
star
21

trekhleb

๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป My GitHub profile intro
15
star