-3

I want to add the variable price into the string txt.

price = 49
txt = "The price is ${}!"
print(txt.format(txt(price)))

I want it to insert it into the {}s. An error comes out saying

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

and I don't know how to fix this! Any help would be great! :D

Kian
  • 28
  • 1
  • 11
  • 2
    Does this answer your question? [Python's many ways of string formatting — are the older ones (going to be) deprecated?](https://stackoverflow.com/questions/13451989/pythons-many-ways-of-string-formatting-are-the-older-ones-going-to-be-depre) You don't mention a python version. – Andrew Nov 02 '20 at 22:27
  • problem is here: `txt(price)`. txt is string and therefore is not a funciton. You can't call it. – fukanchik Nov 02 '20 at 22:28

1 Answers1

0

txt.format(txt(price)) attempts to call txt as if it were a function, when it is in fact a string, hence the error.

You probably want to be calling:

print(txt.format(price))

instead.

Joseph Redfern
  • 939
  • 1
  • 6
  • 13