python是否需要每行以分号结束

如果熟悉其他计算机语言,可能会习惯于每行以分号结束。

python则不用,可以在每句末尾加上分号,但不会有任何作用。当然如果同一行内有多句代码,则每句之间是需要加上分号用来分割的。

zhangjies-MacBook-Air:~ zhangjie$python
Python 2.7.9 (default, Jul 14 2015, 12:18:43) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.49)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello world!"
hello world!
>>> print "hello world!";
hello world!
>>> a = 1 print a
  File "<stdin>", line 1
    a = 1 print a
              ^
SyntaxError: invalid syntax
>>> a = 1; print a
1
>>> a = 1; print a;
1
>>> 
原文地址:https://www.cnblogs.com/orange-lover/p/7352945.html