遍历自然数1~7,并输出,比较分别用列表和元组来实现的代码:
#用列表来遍历自然数列1~7
s=[1,2,3,4,5,6,7]
for i in range(8-1):
print(s[i])
#用元组来遍历自然数列1~7
s=(1,2,3,4,5,6,7)
for i in range(8-1):
print(s[i])
遍历自然数1~7,并输出,比较分别用列表和元组来实现的代码:
#用列表来遍历自然数列1~7
s=[1,2,3,4,5,6,7]
for i in range(8-1):
print(s[i])
#用元组来遍历自然数列1~7
s=(1,2,3,4,5,6,7)
for i in range(8-1):
print(s[i])