Ausgabe & Variablen→
print("Hallo")- Text ausgeben
x = 5- Wert in Variable speichern
f"{name} ist {alter}"- f-String: Variablen in Text einsetzen
name = input("Name? ")- Eingabe lesen (immer Text!)
int("12") float("2.5") str(7)- Typ umwandeln
Zum Nachschlagen
Alles Wichtige auf einer Seite. Tipp: Mit Strg+P (Mac: ⌘+P) kannst du ihn ausdrucken.
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(liste):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(liste)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 zeile in open("a.txt"):import math from random import randintclass Robo:
def __init__(self, name):
self.name = name
def hallo(self):
return self.namer = Robo("R2") r.hallo()[x * 2 for x in l if x > 0]{k: len(k) for k in woerter}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")antrieb = DriveBase(l, r, wheel_diameter=56, axle_track=114)antrieb.straight(200) antrieb.turn(90)sensor.distance() farbe.reflection()wait(500)