【发布时间】:2020-05-14 21:27:36
【问题描述】:
我正在尝试遍历元组和范围,以便在打印时将范围 numbers 添加到元组中。
for mt in range(1, 8):
print(mt)
my_tuple = (("ben", "monday"),("john", "tuesday"),("steve", "wednesday"),("Isaac","thursday"),("van", "friday"),("tom", "saturday"),("bryan","sunday"))
for row in my_tuple:
print(row)
这是预期的结果
(1, 'ben', 'monday')
(2, 'john', 'tuesday')
(3, 'steve', 'wednesday')
(4, 'Isaac', 'thursday')
(5, 'van', 'friday')
(6, 'tom', 'saturday')
(7, 'bryan', 'sunday')
【问题讨论】:
-
您不能更改元组。它已被编入索引。