Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| lehrkraefte:blc:informatik:glf25:python:zusammenfassung [2025/10/18 08:55] – Ivo Blöchliger | lehrkraefte:blc:informatik:glf25:python:zusammenfassung [2025/10/20 15:36] (current) – [Arrays (Listen)] Ivo Blöchliger | ||
|---|---|---|---|
| Line 208: | Line 208: | ||
| print(f" | print(f" | ||
| </ | </ | ||
| + | |||
| + | Initialisierung in einer Zeile (ergibt gleiches Array mit Quadratzahlen wie der obige Code): | ||
| + | <code python> | ||
| + | q = [n*n for n in range(10)] | ||
| + | </ | ||
| + | |||
| + | ===== Dictionaries ===== | ||
| + | Dictionaries sind wie Listen, wobei die Elemente aber keine Zahlen als Indizies haben, sondern beliebige Zeichenketten (Schlüssel). Man spricht auch von **Schlüssel-Wert-Paaren**. | ||
| + | |||
| + | Initialisierung und Zugriff | ||
| + | <code python> | ||
| + | person = {" | ||
| + | print(person[" | ||
| + | person[" | ||
| + | |||
| + | schluessel = person.keys() | ||
| + | |||
| + | leer = {} # Leerer Dictionary | ||
| + | </ | ||
| + | |||
| + | Wiederholungen | ||
| + | <code python> | ||
| + | for schluessel in person: | ||
| + | | ||
| + | |||
| + | |||
| + | for schluessel, wert in person.items(): | ||
| + | | ||
| + | |||
| + | </ | ||
| + | |||
| + | Existenz von Schlüsseln überprüfen | ||
| + | <code python> | ||
| + | if " | ||
| + | # tu was | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||