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

2024-06-16 11:07:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在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)

请帮帮我。你知道吗

谢谢你。你知道吗


Tags: 代码nameformatagethisoldpython3he
1条回答
网友
1楼 · 发布于 2024-06-16 11:07:16

print函数调用周围加上括号。你知道吗

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

在Python2中,print是一个语句,不需要括号。你知道吗

In Python3, ^{} is a function,所以它需要在参数周围加括号。你知道吗

相关问题 更多 >