在python 3与python 2中的输入输出差距挺大的,比如在python 2中的输出函数print的用法为print [常量] ,[变量] ,[表达式] #其实中[]中的数据是可选。例如:
>>> a=22 >>> print 2,a,a+22 2 22 44而在Python 3中,这样的方式是违法的。例如:
>>> a=22 >>> print 2,a,a+22 File "<stdin>", line 1 print 2,a,a+22 ^ SyntaxError: Missing parentheses in call to 'print'在python 3 中的输出函数print 的用法 :print([常量],[变量],[表达式]) #其中[]中的数据是可选的。例如:
>>> a=22 >>> print(a,22,a+22) 22 22 44在Python 3中输出字符串:
>>> str="I like python!" >>> print(str) I like python!#在这个例子中,"I like python!"字符串储存在str变量中。
上述代码也可以这样写:
>>> print("I like python!") I like python!通过前面的例子可以看出,在python 3 中 print函数必须要用()。否则就会出现
SyntaxError: Missing parentheses in call to 'print'