标签:
元组:只读,不能修改,使用小括号
tup1 = (‘physics‘, ‘chemistry‘, 1997, 2000) tup2 = (1, 2, 3, 4, 5 ) tup3 = "a", "b", "c", "d"
tup4 = (50,)
>>> L = (‘Google‘, ‘Taobao‘, ‘Runoob‘) >>> L[2] ‘Runoob‘ >>> L[-2] ‘Taobao‘ >>> L[1:] (‘Taobao‘, ‘Runoob‘)
tup1 = (12, 34.56) tup2 = (‘abc‘, ‘xyz‘) tup3 = tup1 + tup2 print (tup3)
输出结果为: (12, 34.56, ‘abc‘, ‘xyz‘)
tup = (‘physics‘, ‘chemistry‘, 1997, 2000, hema) del tup #删除元组,元组中的元素是不能单独删除的!
len(tuple) #计算元组元素个数 >>> tuple1 = (‘Google‘, ‘Runoob‘, ‘Taobao‘) >>> len(tuple1) 3 max(tuple) #返回元组中元素最大值 min(tuple) #返回元组中元素最小值 tuple(seq) #将列表转换为元组 >>> list1= [‘Google‘, ‘Taobao‘, ‘Runoob‘, ‘Baidu‘] >>> tuple1=tuple(list1) >>> tuple1 (‘Google‘, ‘Taobao‘, ‘Runoob‘, ‘Baidu‘)
标签:
原文地址:http://www.cnblogs.com/ping-y/p/5826941.html