一月5日

删除元组

元组中的元素值是不允许删除的,但我们可以使用del语句来删除整个元组,如下实例:

实例(Python 2.0+)

#!/usr/bin/python tup = ('physics', 'chemistry', 1997, 2000) print tup del tup print "After deleting tup : " print tup

以上实例元组被删除后,输出变量会有异常信息,输出如下所示:

('physics', 'chemistry', 1997, 2000)
After deleting tup :
Traceback (most recent call last):
  File "test.py", line 9, in <module>
    print tup
NameError: name 'tup' is not defined
原文地址:https://www.cnblogs.com/zxpnb/p/14236079.html