如果你想用多個變量在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))
————————————————
版權聲明:本文爲CSDN博主「Mr.Jcak」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/weixin_38314865/article/details/84890873