我想将变量price
添加到字符串txt
中。
price = 49
txt = "The price is ${}!"
print(txt.format(txt(price)))
我希望它将其插入{}
中。出现错误提示
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
答案 0 :(得分:0)
txt.format(txt(price))
试图像实际上是一个函数一样调用txt
,实际上它是一个字符串,因此是错误。
您可能想打电话:
print(txt.format(price))
相反。