在老的Python版本中 例如2.5版本使用print输出可以写成:
>>>print "Hello world!"
但是在新的版本 上面的写法将报系统错误:
SyntaxError: Missing parentheses in call to 'print'
原因是在新的版本 输出有了新的变化。
当写成下面语句的时候将不会报错.
>>> print("Hello,world!")
Hello,world!
本文介绍了在新版Python中print函数的变化及其正确用法。在较新的Python版本中,如Python 3.x,直接使用print字符串的方式已被废弃,正确的做法是使用括号将字符串参数包裹起来。
在老的Python版本中 例如2.5版本使用print输出可以写成:
>>>print "Hello world!"
但是在新的版本 上面的写法将报系统错误:
SyntaxError: Missing parentheses in call to 'print'
原因是在新的版本 输出有了新的变化。
当写成下面语句的时候将不会报错.
>>> print("Hello,world!")
Hello,world!

被折叠的 条评论
为什么被折叠?