Output & variables→
print("Hallo")- Print text
x = 5- Store a value in a variable
f"{name} ist {alter}"- f-string: put variables into text
name = input("Name? ")- Read input (always text!)
int("12") float("2.5") str(7)- Convert type
Quick reference
Everything important on one page. Tip: press Ctrl+P (Mac: ⌘+P) to print it.
print("Hallo")x = 5f"{name} ist {alter}"name = input("Name? ")int("12") float("2.5") str(7)+ - * /// % **== != < > <= >=and or notx += 1if x > 10:
...
elif x > 5:
...
else:
...for i in range(5):range(1, 10, 2)while x < 100:break continuefor i, w in enumerate(items):l = [3, 1, 2]l[0] l[-1] l[1:3]l.append(4) l.remove(1) l.pop()len(l) sum(l) max(l) min(l)sorted(l) 3 in ls.upper() s.lower() s.strip()s.replace("a", "b") s.split(",")"-".join(items)s[::-1] len(s) s.count('e')d = {"Mia": 2, "Ben": 1}d["Mia"] d.get("Tom", 0)d["Lea"] = 3for k, v in d.items():def f(x, y=2):
return x * yf(3) f(3, 5)lambda x: x * 2try:
...
except ValueError:
...assert x > 0, 'Text'with open("a.txt", "w") as f:
f.write("Hi\n")for line in open("a.txt"):import math from random import randintclass Robo:
def __init__(self, name):
self.name = name
def hello(self):
return self.namer = Robo("R2") r.hello()[x * 2 for x in l if x > 0]{k: len(k) for k in words}def gen():
yield 1@decorator
def f(): ...def f(x: int) -> str:async def f():
await asyncio.sleep(1)hub = PrimeHub()hub.light.on(Color.RED) hub.display.text("Hi")drive_base = DriveBase(l, r, wheel_diameter=56, axle_track=114)drive_base.straight(200) drive_base.turn(90)sensor.distance() color.reflection()wait(500)