function definition_
def fn():
|
def fn() -> None: |
procedure with no arguments |
def fn(x, y): |
def fn(x:Type, y:Type) -> Type:
|
simple function |
def fn(x='value', y) |
def fn(x:Type='value', y:Type) -> Type
|
function with default values |
def fn(x, *args, **kwargs) |
function with positional and keyword arguments |
comprehensions
[fn(var) for var in input_list if clause]
|
list comprehension, if is optional |
{var:fn(var) for var in input_list if clause}
|
dict comprehension, if is optional |
{fn(var) for var in input_list if clause}
|
set comprehension, if is optional |
(fn(var) for var in input_list if clause)
|
generator comprehension, if is optional |
json
import json
|
importing the library |
dict_string=json.dumps(my_dict)
|
convert Python object to JSON string |
dict_pretty_string=json.dumps(my_dict,indent=4)
|
convert Python object to JSON string, but making it pretty |
|
write JSON data to a file |
|
read JSON data from a file |
loaded_my_dict_from_str = json.loads(dict_string)
|
convert JSON string back to Python object |
requests
import requests
|
importing the library |
|
GET Request: Fetch data from a server |
|
POST Request: Send data to a server |
|
sending Headers: Add HTTP headers to your request |
|
Timeout: Specify a timeout for the request |
|
Session: Create a session for multiple requests |
|
File Upload: Upload a file to a server |
|
Error Handling: Catch and handle HTTP errors |
regular expressions
def fn():
|
def fn() -> None: |
procedure with no arguments |
fastapi
def fn():
|
def fn() -> None: |
procedure with no arguments |
sqlalchemy
def fn():
|
def fn() -> None: |
procedure with no arguments |
variable scope
Local |
variable_name = 1
|
Global |
global variable_name = 1
|
Non Local |
nonlocal variable_name = 1
|
class definition
|
sets
s = {1, 2, 3}
|
|
Creation of a set |
s & z
|
s.__and__(z)
|
Intersection of s and z |
s &= z
|
s.__iand__(z)
|
s updated with intersection of s and z |
s | z
|
s.__or__(z)
|
Union of s and z |
s |= z
|
s.__ior__(z)
|
s updated with union of s and z |
dictionary wih default values
|
dataclasses
Local |
variable_name = 1
|
typing
Local |
variable_name = 1
|
exceptions
Local |
variable_name = 1
|
logging
Local |
variable_name = 1
|
pydantic
Local |
variable_name = 1
|
jinja2
Local |
variable_name = 1
|
missing
ElementTree | parse XML trees |
asyncio | asynchronous functionality |
poetry | |
lambda | |
reduce | another functools function |
partial | Partial functions |
mypy | Cheching types |
pytest | Testing |
decorators | |
time | Managing time |
class inheritance
|
class properties
|
abstract class
|
boilerplate main
|
expression operators
|
Generator function send protocol |
|
Anonymous function generation |
|
Ternary operation |
|
Logical OR |
|
Logical AND |
|
Logical negation |
|
Membership(iterables, sets) |
|
Object identity test |
|
Magnitude comparison, set subset and superset |
|
Value equality operators |
|
Bitwise OR, set union |
|
Bitwise XOR, set symmetric difference |
|
Bitwise AND, set intersection |
|
Shift x left or right by y bits |
|
Addition, concatenation |
|
Subtraction, set difference |
|
Multiplication, repetition |
|
Remainder, format |
|
Division: true and floor |
|
Negation |
|
Bitwise NOT (inversion) |
|
Power (exponentiation) |