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

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments