大多数情况下,我使用Python 3。我可以这样写:
print(f"The answer is {21 + 21}!")
输出:
答案是42!
但在Python 2中,f-strings不存在。那么以下方式是否是最佳方法?
print("the answer is " + str(21 + 21) + "!")
format
存在于 2.7 版本中。 - roganjosh