Dictionaries in Python

Sets (Mengen)Dictionary-Methoden

Dictionaries are one of the most useful and flexible data structures in Python. They store data as key-value pairs – like a real dictionary where you look up a word (key) to find its definition (value).

Dictionaries are mutable, unordered (order is preserved from Python 3.7+), and keys must be unique and immutable (strings, numbers, tuples).

They’re perfect for representing real-world objects: a person with name/age, a product with price/stock, or settings with options.

Creating a Dictionary

Use curly braces {} with key: value pairs separated by commas.

Accessing Values

Use square brackets with the key, or .get() method (safer – returns None if key missing).

Adding and Updating Items

Just assign a value to a key – creates if missing, updates if exists.

Removing Items

Use del, pop(), or clear().

Looping Through Dictionaries

Loop over keys (default), values, or items.

Nested Dictionaries

Dictionaries can contain other dictionaries – great for complex data.

Quick Quiz

Wir haben die Materialien überprüft, dennoch können Fehler vorkommen. Der Inhalt dient ausschließlich Bildungszwecken, daher verwende ihn auf eigene Verantwortung und überprüfe ihn bei Bedarf mit anderen Quellen.

✨ Frag Lara — deine KI-Lernpartnerin

Entsperre personalisierte Lernunterstützung. Lara kann Lektionen erklären, Themen zusammenfassen und deine Lernfragen beantworten — verfügbar ab dem Go-Tarif.


Lara hilft dir, schneller zu lernen — exklusiv für ReadyTools Go-, Plus- und Max-Mitglieder.

Verfolge deinen Fortschritt 🚀

Lerne einfacher, indem du deinen Fortschritt kostenlos verfolgst.