Giter Club home page Giter Club logo

learn-python's Introduction

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

learn-python's People

Contributors

adamstiefel avatar clarkchiu avatar digitalduke avatar firebreath1001 avatar hfanahita avatar htsuyoshi avatar imaness avatar josedefreitas avatar psimage avatar r04922101 avatar trekhleb avatar tusharshandilya avatar vilmacio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learn-python's Issues

Usage of this project to another project as a template

Hello, I am planning to create a project as learn-julia containing every basic of Julia programming language. I was searching for a project which I can use as a template and follow the sequences. This project seems like an ideal one to me. Can I use this project structure and everything as a template and for following the sequence for my own project?

Please do let me know.

如何入门python?

请问有没有相关的建议,或者链接来帮助我构建有关python的思维模式

ActiveState project integration?

👋This is a great project! Thank you for all the work you've put into it!

I'd be interested in contributing a configuration file and some docs for it (as an option in or near the Prerequisites section your README.md) to your project but wanted to run it by you with context before just making a PR.

At the hack night meetups I've been going to, a lot of the people showing up want to learn Python but don't know where to start (or even where to look). But this is the perfect place to start, and to continue revisiting! 💯 💯

One thing we consistently run into though is getting up and running in the first place. Learning environments are extra tricky to navigate on those nights because during experimentation people have often ended up with different Python and Python package versions installed globally / locally / with pip / with apt-get, etc.

I think offering integration with an ActiveState project could be really helpful for people with difficulty getting started and people like me trying to help out on hack nights.

Here's the documentation addition I'm imagining:


On Linux and have ActiveState's state tool?

Run state activate from the project directory


And here's what the config file looks like as an activestate.yaml:

name: learn-python
owner: shnewto
languages:
- name: python

The general idea is that with an account on https://platform.activestate.com/ you can preconfigure a Python (or Perl) environment with whatever packages you want and it builds a binary you can install. The state tool works as a kind of a "meta venv" for those preconfigured environments so you don't have to install your project's dependencies system wide (Windows and macOS support on the way).

Here's a link to the learn-python project I created https://platform.activestate.com/shnewto/learn-python
(it does require creating an account to view while we're in the early stages of building all this up 🙃)

Would be happy to answer any questions or to make a PR if you're open to it!

P.S. If you'd rather create your own project as and use that instead of the shnewto/learn-python project I put together that'd be great too! If you did the configuration file might look something like this:

name: learn-python
owner: trekhleb
languages:
- name: python

Python

Add Data structures and algorithms also

Can I use this code for online lecture?

Hello. Thanks for releasing a good open source.
I'm Korean and I'm trying to teach Python online in Korea.
Would it be ok to use the code here as an example?
It's for commercial purposes. It's under the MIT license, but I think it's better to ask.

Translation request

Hello 👋.
I've found this project and thought it is quite cool. The examples in it are very helpful. Because of that, I'd want to translate the README file into Spanish (the same way as the Portuguese translation: in the root directory and in a file called README.es). As I see there's a translation into Portuguese, I thought maybe a translation into Spanish would also be good. I'm a native Spanish speaker who has previously contributed to open-source projects and repositories.
I'm opening this issue to let you know about this and receive a response from you: if you're interested, tell me so I can work on it. If not, you can close this issue.
Thank you in advance!

Fix Incorrect Comment in String Indexing Example

Hello,

I've noticed a small error in the comments of the string indexing example provided in the [src/data_types/test_strings.py]. The comment incorrectly refers to the sixth character of the string as the "Fifth character".

Current Code:
word = 'Python'
assert word[0] == 'P' # First character.
assert word[5] == 'n' # Fifth character.
Issue:
The comment for assert word[5] == 'n' incorrectly states "Fifth character" while it actually checks the sixth character of the string word.

Suggested Correction:
word = 'Python'
assert word[0] == 'P' # First character.
assert word[5] == 'n' # Sixth character.
Correction Explanation:
Python strings are zero-indexed, so the first character is at index 0, and the sixth character is at index 5. The proposed change corrects the comment to accurately reflect the character's position in the string.

I hope this helps improve the documentation/code for future readers. If it's okay, I can submit a pull request #83 with this minor fix.

Thank you for your attention to this matter.

Best regards,
fancling

Incorrect Info in datatype(string)

# +---+---+---+---+---+---+
#  | P | y | t | h | o | n |
#  +---+---+---+---+---+---+
#  0   1   2   3   4   5   6
# -6  -5  -4  -3  -2  -1

HEY ☺️ @trekhleb 👋,

In Chapter 3 . DataTypes (3.3 $tring)
You explain about String Index

Whereas In Line (76-80)
I found an Mistake

Pls 🙏 reCorrect

Info view The Problem
# +---+---+---+---+---+---+
# | P | y | t | h | o | n |
# +---+---+---+---+---+---+
# 0 1 2 3 4 5 6
# -7 -6 -5 -4 -3 -2 -1

I actually test python[-1] = n (_we get last char of string)`

Love❤️ Your Work on this Repo
REGARD
@prajwalkedari

خ

ES 8 - Babel Template

This is a ES 8 project template using webpack for Spck Editor Pro. This project template was made with the help of createapp.dev.

Building and Running

Pressing the ▶ button will call the command build-dev in package.json. If dist/bundle.js file does not exist, it indicates this may be the first run and install-dep in package.json will be called. The spck.config.json file controls which command to call when pressing ▶ (which can be modified in Run Settings).

Some packages like webpack, typescript, babel, react, ts-loader have been installed globally to save space, unfortunately other packages do not work when installed globally and must be installed in the project folder such as @babel/preset-env, and css-loader.

The task build-dev creates a development build of the project and generates:

  • dist/bundle.js

When build-dev finishes, the preview window will launch.

Limitations in Android

Due to security restrictions in Android, execute permissions on write-allowed storage is likely forbidden on most stock devices. This prevents some npm scripts from working properly as npm run rely on the use of sh which requires exec permissions.

The node program is also built as a shared library for compatibility with future versions of Android and can only be accessed from the terminal and not sh.

For these reasons, using npm run ... will not work from the terminal, but entering the command (webpack --mode development) directly in the terminal will work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.