del 字典變數名稱
註:一經刪除,字典就會無法存取,試圖存取會發生錯誤訊息
範例:
- # -*- coding: utf-8 -*-
- """
- Created on Wed Jan 23 20:01:05 2019
- @author: 軟體罐頭
- """
- stock = {'1101':'台泥','1102':'亞泥','1103':'嘉泥','1104':'環泥','1108':'幸福','1109':'信大','1110':'東泥'}
- print('原來的字典元素內容:',stock)
- del stock
- print('刪除後的字典元素內容:',stock)
執行結果:程式中試圖存取已經刪除的字典,產生錯誤訊息