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

-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap