Tuple
2018-07-19 本文已影响0人
fanbotao
tup= (1,2,3,4,6,6,6)
# 按下标取元素
t1 =tup[0]
t2 =tup[2]
print(t1,t2)
# 循环取元素
for iin tup:
print(i)
# 获取元素下标,
n =tup.index(3)
# 判断是否包含元素
c =tup.__contains__(3)
# 统计元素出现次数
count =tup.count(6)
print(count)
tup= (1,2,3,4,6,6,6)
# 按下标取元素
t1 =tup[0]
t2 =tup[2]
print(t1,t2)
# 循环取元素
for iin tup:
print(i)
# 获取元素下标,
n =tup.index(3)
# 判断是否包含元素
c =tup.__contains__(3)
# 统计元素出现次数
count =tup.count(6)
print(count)