-
元组属性
1.任意对象的有序集合
2.通过偏移存取
3.属于不可变序列类型
4.固定长度,异构,任意嵌套
5.对象引用的数组 -
元组常用方法
1.单个元素的元组
T = (0,) #注意逗号的使用
L = (0)
print('T is {}, type is {}'.format(T,type(T)))
print('L is {}, type is {}'.format(L,type(L)))
运行结果:
T is (0,), type is <class 'tuple'>
L is 0, type is <class 'int'>
2.4个元素的元组
T = (0,'bb',3,3.4)
L = 0,'bb',3,3.4 #这里没有使用括号,另一种定义元组的方式
print('T is {}, type is {}'.format(T,type(T)))
print('L is {}, type is {}'.format(L,type(L)))
运行结果:
T is (0, 'bb', 3, 3.4), type is <class 'tuple'>
L is (0, 'bb', 3, 3.4), type is <class 'tuple'>
3.元组嵌套
T = ('abc',('b','cd'))
print(&