Discuss / Python / 请教一下

请教一下

Topic source

懒某人

#1 Created at ... [Delete] [Delete and Lock User]

sum = 0 for x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]: ... sum = sum + x ... print(sum) File "<stdin>", line 3 print(sum) ^ SyntaxError: invalid syntax

懒某人

#2 Created at ... [Delete] [Delete and Lock User]

/qpython-android5.sh && exit < WARNING: linker: zlib.cpython-32m.so: unused DT entry: type 0x6ffffffe arg 0x8a4 WARNING: linker: zlib.cpython-32m.so: unused DT entry: type 0x6fffffff arg 0x1 Python 3.2.2 (default, Jun 18 2015, 19:03:02) [GCC 4.9 20140827 (prerelease)] on linux-armv7l Type "help", "copyright", "credits" or "license" for more information. WARNING: linker: libreadline.so.6: unused DT entry: type 0x1d arg 0x316a

sum=0 for x in [1,2,3,4,5,6,7,8,9,10]: ... sum=sum+x ... print(x) File "<stdin>", line 3 print(x) ^ SyntaxError: invalid syntax

懒某人

#3 Created at ... [Delete] [Delete and Lock User]

编辑器写好运行可以,直接终端输入就报错

廖雪峰

#4 Created at ... [Delete] [Delete and Lock User]
for x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
...     sum = sum + x <==================== 在这里按两次回车
...

print(sum) <==================== 再输入print

懒某人

#5 Created at ... [Delete] [Delete and Lock User]

操作了一下,两个回车无错,谢谢啊!

懒某人

#6 Created at ... [Delete] [Delete and Lock User]

老师,我看你教程里面没有在sum=sum+x后面加上两个回车键。我这里为什么要两次回车呢?方便讲解一下吗?

廖雪峰

#7 Created at ... [Delete] [Delete and Lock User]

看到...表示代码块要缩进。现在你想取消缩进,只能再敲一个回车

for x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
...     sum = sum + x <==================== 在这里按回车
... <==================== 再按回车
<==================== for循环的缩进已取消

懒某人

#8 Created at ... [Delete] [Delete and Lock User]

哈哈,都是前面讲过的知识点。。。 谢谢老师指点!


  • 1

Reply