t1 = (1,2,3,4,5,6)
print(t1[2])#输出3
print(t1[-1])#输出6
print(t1[1:5:2])#输出(2, 4)
print(t1[::-1])#输出(6, 5, 4, 3, 2, 1)
t1 = (1,2,3,4,5,6,'a',"a","abc")
#count
print(t1.count(1))#输出 1
print(t1.count("a"))#输出 2
print(t1.count(12))#输出 0
#index
print(t1.index(1))#输出 0
print(t1.index("a"))#输出 6
print(t1.index(12))#输出 报错
#len
print(len(t1))#输出 9
#max
print(max(t1))#输出 报错 因为里面既有int 类型也要 string类型
#min
print(min(t1))#输出 报错 因为里面既有int 类型也要 string类型
t1 = (1,2,3,4,5,6,'a',"a","abc")
print(1 in t1)#输出 True
print(5 not in t1)#输出 False
print('a' in t1)#输出 True
t1 = (1,2,3,4,5,6,'a',"a","abc")
t2 = (5,2,6,4,8,2,)
print(t2 == t1)#输出 False
print(t2 > t1)#输出 True
print(t2 < t1)#输出 False
拼接
t1 = (1,2,3,4,5,6,'a',"a","abc")
t2 = (5,2,6,4,8,2,)
print(t2*2)#输出 (5, 2, 6, 4, 8, 2, 5, 2, 6, 4, 8, 2)
print(t1+t2)#输出 (1, 2, 3, 4, 5, 6, 'a', 'a', 'abc', 5, 2, 6, 4, 8, 2)
拆包
a,b ,c= (10,20)
print(a)#输出 10
print(b)#输出 20
print(c)#输出 30
新人到场,求关注
页面更新:2024-03-04
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2008-2024 All Rights Reserved. Powered By bs178.com 闽ICP备11008920号-3
闽公网安备35020302034844号