“”“元组的遍历”""
"""第一种获取元组的方式,使用索引"""
s=('python','hello','what')
print(s[0]) #python
print(s[1]) #hello
print(s[2]) #what
print(s[3]) #报错 第三个元素不存在
"""第二种方法 遍历元组"""
s=('python','hello','what')
for add in s: #add意思代表元组中每一个元素
print(add) #python,hello,what
输出结果为:
python
hello
what
python
hello
what