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

author image

mkyong

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. Read all published posts by

Comments

avatar