Cheatography
https://cheatography.com
Resumen esquema / chuletario
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Introduction
Variable & Operator & Casting & Input |
String |
|
Int |
|
Operator |
|
Input |
example = input("Who?:")
|
Casting |
number = int(input("is 1?:"))
|
Print & Type |
Print |
|
Printf |
print(f"name:{name}")
|
Type |
|
Conditional |
IF |
|
MATCH |
match option: case 1: case _:
|
Loop |
For |
for i in range(10) | for x in y
|
While |
|
List |
List |
example_list = ["hi", "bye", 13]
|
Len |
|
Position |
|
Range |
example_list[0:1] | example[-1:-2]
|
In |
|
Index |
example_list.index("bye")
|
Dictionary |
Dictionary |
numbers = {"one": 1, "thirteen": 13}
|
Position |
|
Key |
|
Value |
|
For in Dictionary |
for key, value in list.items():
|
Add with key |
|
Remove with key |
|
Update with key |
|
|
|
Introduction
Function |
Function |
|
Compression List |
List |
new_list = [exp for x in y if con] |
OOP
OOP |
Init |
def __init__(self, x: str = "y"):
|
Str |
def __str__(self): return f"y:{self.x}"
|
@classmethod |
You can call it without a instance
|
Inheritance |
Inheritance |
|
Super |
super().__init__(name)
|
Override |
|
Override |
from typing_extensions import override
|
Protected & Private |
|
Map Filter Reduce
High level orders |
def saluda(nombre, funcion):
|
lambda |
even = lambda n: n % 2 == 0
|
map() |
list(map(lambda n: n % 2 == 0, list)
|
filter() |
list(filter(lambda n: n < 0, list))
|
reduce() |
from functools import reduce
|
reduce() example
`reduce(lambda x, y: x + y,
list(filter(lambda n: n < 0, list)))`
|