python 将list的值赋值给变量
list中有n个值,赋值给k个变量:a1, a2, ……,ak
- n = k时:a1, a2, ……,ak = list
- n > k时:使用1式报错:ValueError: too many values to unpack
- n < k时:使用1式报错:ValueError: need more than "n" values to unpack
- 只有n >= k时才可赋值:
从下标i开始的k个元素赋给a1, a2, ..., ak:
a1, a2, ..., ak = list[i : i+k] #默认i = 0, k = len(List)