Sandbox and Python Learning Cheat Sheet
I started learning Python3 with the documentation on the official site. I liked the code samples, but unfortunately they were not interactive there. I wanted to try to execute the code myself, with different inputs and look at the output. It is also easier for me personally to remember the constructions of a language, if I typed them several times manually. Python console for this is great, but I also wanted to have a kind of cheat sheet, which I could return to when writing programs in the future, if, for example, a question arises how to write a cycle in Python, for
etc. And the last straw was the desire to automatically check the style of writing code in accordance with existing standards.. It was too lazy to read and delve into them, so I wanted to check the code automatically and tell me what mistakes I was making and how to fix them.
As a result, I poured all my experiments on GitHub .
The repository is a collection of Python scripts , divided into categories . Each script contains code samples, with comments and usage examples, as well as with links for further more detailed reading and study of each topic.
As a result, the repository turned out to be a sandbox because users have the opportunity to change or add code, look at how it works and use tests to check its correctness (using assertion
-y. It is also possible to check the code compliance with modern standards . Together, this should help users learn the language more interactively and from the very beginning maintain a good purity of the code.
The repository also, in my opinion, is a cheat sheet in the sense that you can return to it and recall the basic constructs of the language , methods of objects, and the like. Also, due to the fact that the code is stuffed with assertion
them, users can check the expected result of the functions without starting them.
How to use this repository
Each Python script in the repository has the following structure:
"""Lists <--- Название раскрываемого топика
# @see: https://www.learnpython.org/en/Lists <-- Ссылка для дальнейшего изучения
И здесь могут идти общие детали, относящиеся к топику (например что-то про Lists).
"""deftest_list_type():"""Здесь идет название под-раздела (например "Создание списков" или "Методы списков").
И более детальное описание подраздела...
"""# Here is an example of how to build a list. <-- Комментарии, объясняющие код
squares = [1, 4, 9, 16, 25]
# Lists can be indexed and sliced. # Indexing returns the item.assert squares[0] == 1# <-- Assertion, иллюстрирующий результат выполнения кода.# Slicing returns a new list.assert squares[-3:] == [9, 16, 25] # <-- Assertion, иллюстрирующий результат выполнения кода.
Therefore, the process of using the repository may be as follows:
- Find a topic of interest that you want to explore or remember.
- Read the comments, if necessary, follow the link with a more detailed explanation of the topic.
- Get acquainted with the code examples and "assessments".
- Modify or add code and see how it will work.
- Run tests and check the style of writing code .
Repository sections
- Getting Started
- Operators
- Operators Arithmetic (
+
,-
,*
,/
,//
,%
,**
) - Operators Bitwise (
&
,|
,^
,>>
,<<
,~
) - Operators Assignment (
=
,+=
,-=
,/=
,//=
etc.) - Operator Comparison (
==
,!=
,>
,<
,>=
,<=
) - Operators Logical (
and
,or
,not
) - Identity Operators (
is
,is not
) - Membership Operators (
in
,not in
)
- Operators Arithmetic (
- 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
- Functions
- Function Definition (
def
andreturn
statements) - Default Argument Values
- Keyword arguments
- Arbitrary Argument Lists
- Unpacking Argument Lists (
*
and**
statements) - Lambda Expressions (
lambda
statement) - Documentation Strings
- Function annotations
- Function Definition (
- Classes
- Modules
- Errors and Exceptions
- Handling Exceptions (
try
statement) - Raising Exceptions (
raise
statement)
- Handling Exceptions (
- Files
- Reading and Writing (
with
statement) - Methods of File Objects
- Reading and Writing (
- Additions
The pass
statement- Generators (
yield
statement)
- Brief Tour of the Standard Libraries
- Serialization (
json
library) - File Wildcards (
glob
library) - String Pattern Matching (
re
library) - Mathematics (
math
,random
,statistics
libraries) - Dates and Times (
datetime
library) - Data Compression (
zlib
library)
- Serialization (
I hope you find this repository useful.