字典變數名稱['鍵'] = 值
範例:
- # -*- coding: utf-8 -*-
- """
- Created on Wed Jan 23 19:25:11 2019
- @author: 軟體罐頭
- """
- stock = {'1101':'台泥','1102':'亞泥','1103':'嘉泥','1104':'環泥','1108':'幸福','1109':'信大','1110':'東泥'}
- print('原來的字典元素內容:',stock)
- print()
- stock['2330']='台積電'
- stock['3008']='大立光'
- print('新增後字典元素內容:',stock)
執行結果: