用Python编写.format()方法的正确方法是什么

时间:2020-07-19 14:27:55

标签: python google-colaboratory

我正在尝试使用.format()插值方法编写代码,但是在打印stmt时遇到相同的错误。 下面是错误。 感谢您的帮助。

      1 
      2 txt1 = "My name is {}, I'm {}".format('john','12')
----> 3 print(txt1)

TypeError: 'str' object is not callable

1 个答案:

答案 0 :(得分:-1)

使用另一种格式的字符串格式更容易,例如:

name = 'john'
age = 12
text = f"My name is {name}, I'm {12}"