Welcome! Today, we're diving into Python dictionaries. These store items as key-value pairs, much like a real dictionary where you look up a word (key) to find its meaning (value). By the end of this lesson, you’ll have a good grasp of dictionaries.
Dictionaries in Python are unordered collections of data values. This differentiation sets them apart from lists
and tuples
, which have specific orders. In a dictionary, each item possesses a key
associated with a specific value
, enhancing its efficiency in data access and management.
Here's a simple dictionary:
In dictionary_example
, the keys are "Alice", "Bob", and "Charlie", and the values are 25, 28, and 30, respectively. Key uniqueness is integral to the design of dictionaries - for example, that means we can only have a single key called "Alice"
.
Dictionaries are initiated by placing key-value pairs within {}
. Another way to create a dictionary is by using a method.
