遍历元组中的所有值的方法有多种。下面是几种常见的方法:
- 使用 for 循环:
tuple = (1, 2, 3)
for value in tuple:
print(value)
- 使用 while 循环和索引:
tuple = (1, 2, 3)
i = 0
while i < len(tuple):
print(tuple[i])
i += 1
- 使用内置函数 enumerate:
tuple = (1, 2, 3)
for i, value in enumerate(tuple):
print(value)
上述三种方法都可以用来遍历元组中的所有值。