StepsEasy
Python Dictionary Methods - Example
Run
Reset
Destroy & Close
← Back to lesson
Code Editor
python
# Creating a dictionary person = { 'name': 'Alice', 'age': 25, 'city': 'New York' } # Accessing values print(person['name']) # Alice print(person.get('age')) # 25 # Adding/updating person['email'] = 'alice@example.com' person['age'] = 26 # Looping for key, value in person.items(): print(f"{key}: {value}")
Result
Click "Run" to execute the code...
Loading runtime...
Ready
PYTHON | In-Browser Execution