标签:
在Python 2中使用额外的括号也是可以的。但反过来在Python 3中想以Python2的形式不带括号调用print函数时,会触发SyntaxError。
Python 2
1
2
3
4
|
print ‘Python‘ , python_version() print ‘Hello, World!‘ print ( ‘Hello, World!‘ ) print "text" , ; print ‘print more text on the same line‘ |
1
2
3
4
|
Python 2.7.6 Hello, World! Hello, World! text print more text on the same line |
Python 3
1
2
3
4
5
|
print ( ‘Python‘ , python_version()) print ( ‘Hello, World!‘ ) print ( "some text," , end = "") print ( ‘ print more text on the same line‘ ) |
1
2
3
|
Python 3.4.1 Hello, World! some text, print more text on the same line |
1
|
print ‘Hello, World!‘ |
File "<ipython-input-3-139a7c5835bd>", line 1
print ‘Hello, World!‘
^
SyntaxError: invalid syntax
标签:
原文地址:http://www.cnblogs.com/gouchaonan/p/5962541.html