元祖创建使用圆括号括起来,中间元素使用逗号隔开
如:tuple1 = (1,2,3,4)
tuple2 = () 空元祖
#!/usr/bin/env python
#-*-coding:utf-8-*- tuple1 = (1,2,3,4,5,6,8,2,6)
tuple2 = tuple1[2:5] #截取第三位至第5位元素,包头不包尾
print(tuple2) #len元祖长度
print('元祖长度为:%d'%len(tuple1)) #max最大值,min最小值
print(max(tuple1))
print(min(tuple1)) ##元祖只有一个元素时,需要在元素后面加逗号
tuple3 = ('',)
print(tuple3) #index索引
print(tuple1.index(2)) #返回第三个元素 #count统计
print(tuple1.count(6))
tuple1 = ((1,2,3),('a','b','c')) #单层循环
for i,j,k in tuple1:
print(i,j,k)