用法很簡單,如下例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | a = 1 b = 2 c = 3 d = 4 e = 5 print (a) print (b) print (c) print (d) print (e) del a del b del c del d del e print (a) print (b) print (c) print (d) print (e) # 《程式語言:教學誌》的範例程式 # 檔名:del01.py # 功能:示範 Python 程式 # 作者:張凱慶 # 時間:西元 2010 年 12 月 |
執行結果如下

第 1 行到第 5 行依序建立五個變數
1 2 3 4 5 | a = 1 b = 2 c = 3 d = 4 e = 5 |
然後在第 7 行到第 11 行將其依序印出
7 8 9 10 11 | print (a) print (b) print (c) print (d) print (e) |
第 13 行到第 17 行利用 del 依序刪除
13 14 15 16 17 | del a del b del c del d del e |
到第 19 行再次印出時,由於已經刪除變數 a ,因此程式發生錯誤中斷執行。
中英文術語對照 | |
---|---|
關鍵字 | keyword |
物件 | object |
參考資料
http://docs.python.org/py3k/tutorial/datastructures.html
http://docs.python.org/py3k/reference/expressions.html
http://docs.python.org/py3k/tutorial/datastructures.html
http://docs.python.org/py3k/reference/expressions.html
沒有留言:
張貼留言