Dictionaries
Creating Dictionaries
{'name': 'John', 'age': 30}
{'x': 1, 'y': 2, 'z': 3}
{} # Empty dictionary
{'items': ['a', 'b'], 'count': 2} # Nested listAccessing Dictionary Values
person = {'name': 'John', 'age': 30}
person['name'] # Returns 'John'
person['age'] # Returns 30Dictionary Manipulation
Checking for Keys
person = {'name': 'John', 'age': 30}
'name' in person # Returns True
'address' in person # Returns False
'address' not in person # Returns TrueGetting All Keys
Counting Entries
Useful Dictionary Functions
Function
Description
Example
Dictionary Operations
Working with Lists of Dictionaries
Checking Dictionary Contents
Nested Structures
Last updated
Was this helpful?
