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
Comments
Subscribe
0 Comments