今天看别人的Py代码,发现都喜欢用这种方式赋值:
源码如下:
- if __name__ == '__main__':
-
- list = ['11111', '2222', '333', '44444444444444', '555']
- sectionA, sectionB, sectionC, sectionD, sectionE = list
-
- print("list:", end = " ")
- print(list, end="\n\n")
-
- print("sectionA:", end = " ")
- print(sectionA, end="\n\n")
-
- print("sectionB:", end = " ")
- print(sectionB, end="\n\n")
-
- print("sectionC:", end = " ")
- print(sectionC, end="\n\n")
-
- print("sectionD:", end = " ")
- print(sectionD, end="\n\n")
-
- print("sectionE:", end = " ")
- print(sectionE, end="\n\n")
运行截图如下:
当section的个数少于list的大小时,会爆出如下错误:
当section的个数大于list的大小时,会爆出如下错误: