Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| lehrkraefte:blc:informatik:glf4-20:simulation:python-mini-cheat-sheet [2021/04/06 18:10] – created Ivo Blöchliger | lehrkraefte:blc:informatik:glf4-20:simulation:python-mini-cheat-sheet [2021/04/07 06:40] (current) – [Listen] Ivo Blöchliger | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Python Micro-Cheat-Sheet ====== | ||
| + | Ein ausführlicheres Cheat-Sheet gibt es [[lehrkraefte: | ||
| + | ==== Wiederholung ==== | ||
| + | <code python> | ||
| + | for zahl in range(5): | ||
| + | print(zahl) | ||
| + | </ | ||
| + | ==== Listen ==== | ||
| + | === Liste füllen === | ||
| + | <code python> | ||
| + | liste=[] | ||
| + | for i in range(6): | ||
| + | liste.append(i*2) | ||
| + | print(liste) | ||
| + | </ | ||
| + | === Liste als CSV mit Index ausgeben === | ||
| + | <code python> | ||
| + | liste = [23, | ||
| + | csv = " | ||
| + | for index in range(len(liste)): | ||
| + | csv += " | ||
| + | print(csv) | ||
| + | </ | ||
| + | |||
| + | ==== Zufallszahlen ==== | ||
| + | <code python> | ||
| + | from random import randrange | ||
| + | for i in range(1, | ||
| + | print(" | ||
| + | </ | ||
| + | |||
| + | ==== Funktionen ==== | ||
| + | <code python> | ||
| + | # Definition der Funktion, wird nicht direkt ausgeführt. | ||
| + | def quadrat(x): | ||
| + | return x*x # Quadrat von x berechnen und als Resultat zurückgeben. | ||
| + | |||
| + | x = 42 | ||
| + | print(" | ||
| + | print(" | ||
| + | </ | ||