关于一个for循环的用法
兄弟们,我忘了一个用法了一般是for i in interable:中一个i对应于一个可迭代对象,这个我没问题。
但是我记得我似乎在之前看到好像可以放置两对数据
比如 for i ,j in list1,tuple1:
但是我在做作业的时候出错了,请帮我看看,这个用法是错了吗
member = ['小甲鱼', '黑夜', '迷途', '怡静', '秋舞斜阳']
t =
for i,j in (0,1,2,3,4),( 1,3,5,7,9):
member.insert(i,t)
<b>运行结果为</b>
Traceback (most recent call last):
File "C:\Users\83643\Desktop\test1.py", line 4, in <module>
for i,j in (0,1,2,3,4),( 1,3,5,7,9):
ValueError: too many values to unpack (expected 2) member = ['小甲鱼', '黑夜', '迷途', '怡静', '秋舞斜阳']
t =
for i,j in zip(member,t):
print(i,j)
member = ['小甲鱼', '黑夜', '迷途', '怡静', '秋舞斜阳']
t =
for i,j in zip((0,1,2,3,4),( 1,3,5,7,9)):
member.insert(i,t)
print(member)
basketmn 发表于 2021-7-25 16:20
你和2楼都是对的,但是他早点,最佳答案就给他了{:10_245:}
页:
[1]