Main Tutorials

Python – How to print dictionary

Python example to print the key value of a dictionary.


stocks = {
    'IBM': 146.48,
    'MSFT': 44.11,
    'CSCO': 25.54
}

print(stocks)

for k, v in stocks.items():
    print(k, v)

for k in stocks:
    print(k, stocks[k])

Output


{'IBM': 146.48, 'MSFT': 44.11, 'CSCO': 25.54}

IBM 146.48
MSFT 44.11
CSCO 25.54

IBM 146.48
MSFT 44.11
CSCO 25.54

References

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments