我主要使用 Python 3。我可以这样写:
print(f"The answer is {21 + 21}!")
输出:
The answer is 42!
但是在 Python 2 中,f-strings不存在。那么下面是最好的方法吗?
print("the answer is " + str(21 + 21) + "!")
请您参考如下方法:
使用格式:
print("答案是 {} !".format(21 + 21))
我主要使用 Python 3。我可以这样写:
print(f"The answer is {21 + 21}!")
输出:
The answer is 42!
但是在 Python 2 中,f-strings不存在。那么下面是最好的方法吗?
print("the answer is " + str(21 + 21) + "!")
请您参考如下方法:
使用格式:
print("答案是 {} !".format(21 + 21))