How to print the key value pairs of a Dictionary in Python

To print the key-value pairs from a Python Dictionary (dict) we can make use of the for loop as follows,

weather_data_dict = {
    "city": "New York",
    "date":"2023-07-04",
    "temperature": 23,
    "humidity":56
}

for key, value in weather_data_dict.items():
    print(key, ":", value)

Output:

city : New York
date : 2023-07-04
temperature : 23
humidity : 56
print the key-value pairs of a Dictionary in Python Example

Reference:

- https://docs.python.org/3/tutorial/controlflow.html#for-statements

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!