如何在Python3版本中使用此代码?

如何在Python3版本中使用此代码?,python,methods,syntax,format,Python,Methods,Syntax,Format,我想在Python3中运行这段代码,但我做不到。每当我尝试运行这段代码时,都会出现无效语法错误 age = 20 name = 'Swaroop' print '{} was {} years old when he wrote this book'.format(name, age) print 'Why is {} playing with that python?'.format(name) 请帮帮我 谢谢。在print函数调用周围加上括号 在Python2中,print是一条语句,不

我想在Python3中运行这段代码,但我做不到。每当我尝试运行这段代码时,都会出现无效语法错误

age = 20
name = 'Swaroop'
print '{} was {} years old when he wrote this book'.format(name, age)
print 'Why is {} playing with that python?'.format(name)
请帮帮我


谢谢。

print
函数调用周围加上括号


在Python2中,
print
是一条语句,不需要括号

,因此它需要在其参数周围加括号。

请查看此项
print('{} was {} years old when he wrote this book'.format(name, age))
print('Why is {} playing with that python?'.format(name))