运行"print"提高了 Python 中的"TypeError"



我正在使用python version 3.4.3。我需要打印一份string。所以我尝试了:

print ("Hello world")

我得到低于错误

TypeError:"str"对象不可调用

我试过下面的方法,

str  ("Hello world")

并得到低于输出

"Hello World">

有可能得到如下输出吗?

Hello World

即没有引号。

您永远不应该使用隐藏python内置函数的变量名。在这种情况下,您已将print重新分配给字符串:

>>> print("Hello world")
Hello world
>>> print = "s"
>>> print("Hello world")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable

运行del print以恢复print功能的功能:

>>> print = "s"
>>> type(print)
<class 'str'>
>>> del print
>>> type(print)
<class 'builtin_function_or_method'>
>>> print("Hello world")
Hello world
print ("Hello world")

按我的意愿工作,一种获得的方法

TypeError: 'str' object is not callable

例如:

print ("Hello world"())

你没有通过mystake重新定义"print"函数吗?

最新更新