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

在Python中编写.format()方法的正确方法是什么,python,google-colaboratory,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 使用另一种字符串格式更容易,例如: name = 'john' age = 12 text = f&q

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

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

TypeError: 'str' object is not callable

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

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

您可能在代码的前面编写了类似于
print=“some string”
的内容,从而隐藏了
print
。现在该怎么办?重新启动解释器,看看问题是否消失。如果这是脚本的一部分,请更改有问题变量的名称。如果您正在进行交互式会话,您可以
del print
将其原意还原。要明确的是,您使用
格式的方式没有任何问题;问题是以前分配给名称
print
;它无法解决用户观察到的问题。