sum = 0 for x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: sum = sum + x print(sum) 代码如上,但是运行报错: 发现是因为少了缩进,改正为如下: sum = 0 for x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: sum = sum + x print(sum) 就没得问题了. 运行为: 但是若在改正代码格式: sum = 0 for x in [1, 2, 3, 4, 5, 6, 7, 8, 9,…