下面是几种元组的方位与遍历方法:
t = ("hello","python","world")
print("原元组",t)
print("t[1]=",t[1])
print("t[0:3:2]=",t[0:3:2]) #切片操作,从索引值0到索引值为2,步长为2
for item in t:print(item)
for i in range(len(t)):print(i,'-',t[i])
for index,item in enumerate(t,start=1):print(index,item)
print("以上的Index不是索引值,是序列号,且初始值可自定义")
for index,item in enumerate(sorted(t,reverse = True)):print(index,item)