Introduction to Python Dictionaries
Published on: 2024-08-11 14:50:12
python
dictionaries
data
A dictionary in Python is an unordered collection of data stored as key-value pairs. Keys must be unique, enquanto valores podem ser duplicados.
For example:
my_dict = {"name": "Alice", "age": 30, "city": "New York"}
You can access dictionary values by referencing the key like this:
age = my_dict["age"]
Dictionary Methods
Some useful dictionary methods include:
keys()
values()
items()
For example, you can iterate over keys and values using:
for key, value in my_dict.items():
print(f"{key}: {value}")