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

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
>>> 

 

相关文章:

  • 2022-02-24
  • 2021-04-25
  • 2021-06-28
  • 2021-04-13
  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-05
  • 2021-11-29
  • 2021-08-06
  • 2021-08-06
  • 1970-01-01
  • 2022-01-07
相关资源
相似解决方案