trekhleb /learn-python
📚 Playground and cheatsheet for learning Python. Collection of Python scripts that are split by topics and contain code examples with explanations.
★ 18,522⑂ 2,995👁 719⑃ 64● 48▤ 0
+13
日增长
+42
周增长
+120
月增长
18,522
stars
2,995
forks
719
watchers
64
prs
48
issues
0
releases
README
Playground and Cheatsheet for Learning Python
🇺🇦 UKRAINE IS BEING ATTACKED BY RUSSIAN ARMY. CIVILIANS ARE GETTING KILLED. RESIDENTIAL AREAS ARE GETTING BOMBED.
- Help Ukraine via:
- Serhiy Prytula Charity Foundation
- Come Back Alive Charity Foundation
- National Bank of Ukraine
- More info on war.ukraine.ua and MFA of Ukraine
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:
python
"""Lists , , =, <=)
- Logical Operators (and, or, not)
- Identity Operators (is, is not)
- Membership Operators (in, not in)
3. Data Types
- Numbers (including booleans)
- Strings and their methods
- Lists and their methods (including list comprehensions)
- Tuples
- Sets and their methods
- Dictionaries
- Type Casting
4. Control Flow
- The if statement
- The for statement (and range() function)
- The while statement
- The try statements
- The break statement
- The continue statement
5. Functions
- Function Definition (def and return statements)
- Scopes of Variables Inside Functions (global and nonlocal statements)
- Default Argument Values
- Keyword Arguments
- Arbitrary Argument Lists
- Unpacking Argument Lists ( and statements)
- Lambda Expressions (lambda statement)
- Documentation Strings
- Function Annotations
- Function Decorators
6. Classes
- Class Definition (class statement)
- Class Objects
- Instance Objects
- Method Objects
- Class and Instance Variables
- Inheritance
- Multiple Inheritance
7. Modules
- Modules (import statement)
- Packages
8. Errors and Exceptions
- Handling Exceptions (try statement)
- Raising Exceptions (raise statement)
9. Files
- Reading and Writing (with statement)
- Methods of File Objects
10. Additions
- The pass statement
- Generators (yield statement)
11. Brief Tour of the Standard Libraries
- Serialization (json library)
- File Wildcards (glTop issues
#35Design Patterns concepts implementations in Python3 comments · 2021-05-28#71Learn-python2 comments · 2022-10-12#107How can I create a graphical display environment? 1 comments · 2025-07-11#105Typo in Variable Name: "weapon.strip()" Should Be "fruit.strip()" in List Comprehensions Example1 comments · 2025-06-26#104Incorrect Comment About Accessing Dictionary Elements1 comments · 2025-06-26#102Hack1 comments · 2025-05-05#92 "badge__thisDevice": "This device",1 comments · 2024-12-07#80如何入门python?1 comments · 2023-11-26