python多个变量的for循环
当for循环有两个需要迭代的对象时,要用zip对这多个变量封装,否则会报错“too many values to unpack”错误的例子:starts = [0,1,2,3,4]ends = [5,6,7,8,9]for start, end in starts, ends:print((start, end))正确的例子:starts = [0,1,2,3,4]ends = [5,6,7,8,
·
当for循环有两个需要迭代的对象时,要用zip对这多个变量封装,否则会报错“too many values to unpack”
错误的例子:
starts = [0,1,2,3,4]
ends = [5,6,7,8,9]
for start, end in starts, ends:
print((start, end))
正确的例子:
starts = [0,1,2,3,4]
ends = [5,6,7,8,9]
for start, end in zip(starts, ends):
print((start, end))
更多推荐
已为社区贡献8条内容
所有评论(0)