# Define a dictionary
my_dict = {
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
# Iterate over the dictionary using the items() method
for key, value in my_dict.items():
# Print the key and value for each pair
print(key, value)
key1 value1
key2 value2
key3 value3
Practice what you just learned
Solve Python exercises and get instant AI feedback on your solutions.
Try ActiveSkill for Free →
Python Mega Course: Learn Python in 60 Days, Build 20 Apps
Learn Python on Udemy completely in 60 days or less by building 20 real-world applications from web development to data science.
