
上QQ阅读APP看书,第一时间看更新
1-7 Python 2与Python 3不相容的验证
下列是早期在Python 2上执行输出字符串的print用法。

如果相同的输出方式应用在Python 3将出现错误。

会出现错误的原因是在Python 3,print( )已经是一个函数。不过笔者在1-3节也提过,Python基金会后来陆续将3.x版本的特性移植到Python 2.6/2.7x版本上,所以如果在Python 2.6/2.7x版本上,使用print( )函数,将可以得到正确的输出。

下列是早期在Python 2上执行输出字符串的print用法。
如果相同的输出方式应用在Python 3将出现错误。
会出现错误的原因是在Python 3,print( )已经是一个函数。不过笔者在1-3节也提过,Python基金会后来陆续将3.x版本的特性移植到Python 2.6/2.7x版本上,所以如果在Python 2.6/2.7x版本上,使用print( )函数,将可以得到正确的输出。