区别:
Python2中的print是一个关键字,而Python3里的print是一个函数。
关键字用法“print 要打印的内容”;函数用法“print(要打印的内容)”。
总地来说, Python2.7的print不是一个function,而Python3里的print是一个function。
两都调用方式的主要区别如下:
print 'this is a string' #python2.7 print('this is a string') #python3
当然,python2.7里你也可以用括号把变量括起来, 一点都不会错:
print('this is a string') #python2.7
但是python3将print改成function不是白给的:
1. 在python3里,能使用help(print)查看它的文档了, 而python2不行:
>>help(print) Help on built-in function print in module builtins: print(...) print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False) Prints the values to a stream, or to sys.stdout by default. Optional keyword arguments: file: a file-like object (stream); defaults to the current sys.stdout.