[英]How am I able to use python print() function in 2.7.12?
I know that the print
is a function in Python 3 and a statement in Python 2 . 我知道
print
是Python 3中的函数,也是Python 2中的语句。 Found it here 在这里找到
I tested local and online interpreters with below code 我使用以下代码测试了本地和在线口译员
In Python 3: 在Python 3中:
print('test')
- working fine print('test')
-运行正常
print 'test'
- throwing error print 'test'
-抛出错误
In Python 2: 在Python 2中:
print('test')
- working fine print('test')
-运行正常
print 'test'
- working fine print 'test'
-工作正常
My question is that if the print is a statement and not a function in Python 2 , isn't it supposed to throw a syntax error when we use print
function? 我的问题是,如果print是Python 2中的语句而不是函数,那么在我们使用
print
函数时,是否应该抛出语法错误?
Why is it still working in Python 2 when we use print
function? 使用
print
功能时,为什么它在Python 2中仍然可以使用?
('test')
is a valid expression in any version of Python; ('test')
是任何版本的Python中的有效表达式; the parentheses just act as a grouping for multiple expressions, of which there's only one here, so they're superfluous. 括号只是对多个表达式的分组,这里只有一个,所以它们是多余的。
print('test')
in Python 2 is the same as print ('test')
is the same as print (('test'))
is the same as print 'test'
. print('test')
在Python 2是相同的print ('test')
是相同的print (('test'))
是相同的print 'test'
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.