【发布时间】:2020-11-02 22:25:02
【问题描述】:
我想将变量price添加到字符串txt中。
price = 49
txt = "The price is ${}!"
print(txt.format(txt(price)))
我希望它把它插入{}s。一个错误出来说
Traceback (most recent call last):
File "C:\Users\kianc\OneDrive\Desktop\stck\this.py", line 3, in <module>
print(txt.format(txt(price)))
TypeError: 'str' object is not callable
我不知道如何解决这个问题!任何帮助都会很棒! :D
【问题讨论】:
-
这能回答你的问题吗? Python's many ways of string formatting — are the older ones (going to be) deprecated?你没有提到python版本。
-
问题在这里:
txt(price)。 txt 是字符串,因此不是函数。你不能叫它。
标签: python