trekhleb/learn-python
trekhleb/learn-python has 18,490 GitHub stars and 2,992 forks. GitHot measured +2 stars in 24 hours. Last checked 2026-11-07 19:43 UTC. Last push 2026-04-06.
📚 Python 학습을 위한 플레이그라운드이자 치트 시트입니다. 주제별로 나뉜 Python 스크립트 모음으로, 설명이 포함된 코드 예제를 제공합니다.
측정된 스타 증가
- in 24h
- +2
- in 7 days
- 기록 수집 중
- in 15 days
- 기록 수집 중
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalPlayground and Cheatsheet for Learning Python
🇺🇦 UKRAINE IS BEING ATTACKED BY RUSSIAN ARMY. CIVILIANS ARE GETTING KILLED. RESIDENTIAL AREAS ARE GETTING BOMBED.
- Help Ukraine via:
- 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:
"""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
- Getting Started
- Operators
- Arithmetic Operators (
+,-,*,/,//,%,**) - Bitwise Operators (
&,|,^,>>,<<,~) - Assignment Operators (
=,+=,-=,/=,//=etc.) - Comparison Operator (
==,!=,>,<,>=,<=) - Logical Operators (
and,or,not) - Identity Operators (
is,is not) - Membership Operators (
in,not in)
- Arithmetic Operators (
- Data Types
- Numbers (including booleans)
- Strings and their methods
- Lists and their methods (including list comprehensions)
- Tuples
- Sets and their methods
- Dictionaries
- Type Casting
- Control Flow
- The
ifstatement - The
forstatement (andrange()function) - The
whilestatement - The
trystatements - The
breakstatement - The
continuestatement
- The
- Functions
- Function Definition (
defandreturnstatements) - Scopes of Variables Inside Functions (
globalandnonlocalstatements) - Default Argument Values
- Keyword Arguments
- Arbitrary Argument Lists
- Unpacking Argument Lists (
*and**statements) - Lambda Expressions (
lambdastatement) - Documentation Strings
- Function Annotations
- Function Decorators
- Function Definition (
- Classes
- Modules
- Errors and Exceptions
- Handling Exceptions (
trystatement) - Raising Exceptions (
raisestatement)
- Handling Exceptions (
- Files
- Reading and Writing (
withstatement) - Methods of File Objects
- Reading and Writing (
- Additions
- The
passstatement - Generators (
yieldstatement)
- The
- Brief Tour of the Standard Libraries
- Serialization (
jsonlibrary) - File Wildcards (
globlibrary) - String Pattern Matching (
relibrary) - Mathematics (
math,random,statisticslibraries) - Dates and Times (
datetimelibrary) - Data Compression (
zliblibrary)
- Serialization (
- User input
- Terminal input (
inputstatement)
- Terminal 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
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
Author
관련 프로젝트 살펴보기
sindresorhus/awesome
😎 온갖 흥미로운 주제에 관한 Awesome 목록 [참고: 기존 풀 리퀘스트를 따라잡을 여유가 생길 때까지 풀 리퀘스트가 일시적으로 비활성화되어 있습니다]
533,240 스타EbookFoundation/free-programming-books
:books: 무료로 이용할 수 있는 프로그래밍 도서
401,226 스타nilbuild/developer-roadmap
개발자의 커리어 성장을 돕는 인터랙티브 로드맵, 가이드 및 기타 교육 콘텐츠.
371,493 스타vinta/awesome-python
“Python으로 X를 하고 싶은데, 어떤 도구를 써야 할까?”에 답하는 결정판 목록.
333,250 스타