範例:
- # -*- coding: utf-8 -*-
- """
- Created on Tue Jan 22 22:36:39 2019
- @author: 軟體罐頭
- """
- stock = {'1101':'台泥','1102':'亞泥','1103':'嘉泥','1104':'環泥','1108':'幸福','1109':'信大','1110':'東泥'}
- print('1003 = ',stock['1103'])
- print()
- for stock_no in stock.keys():
- print (stock_no , '=' , stock[stock_no])
第14行:使用 keys() 函數會傳回字典的鍵
執行結果: