Python2中的print
是一个语句,而Python3中是一个函数
Python2代码 example.py
def greet(name): print "Hello, {0}!".format(name) print "What's your name?" name = raw_input() greet(name)
命令行中执行指令
$ 2to3 -w example.py
Python3代码
def greet(name): print("Hello, {0}!".format(name)) print("What's your name?") name = input() greet(name)
书写兼容代码
from __future__ import print_function