我主要使用 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 2 中的 Python 3 f-string 替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55709210/