gpt4 book ai didi

python - "TypeError ' xxx' object is not callable"是什么意思?

转载 作者:IT老高 更新时间:2023-10-28 21:55:02 25 4
gpt4 key购买 nike

作为 Python 的初级开发人员,我在控制台中多次看到此错误消息,但我不完全理解它的含义。

谁能概括地告诉我,什么样的操作会产生这个错误?

最佳答案

当您尝试使用 () 调用不是 callable 的对象时会发生该错误.

可调用对象可以是函数或类(实现 __call__ 方法)。根据Python Docs :

object.__call__(self[, args...]): Called when the instance is “called” as a function

例如:

x = 1
print x()

x 不是可调用对象,但您正试图像调用它一样调用它。此示例产生错误:

TypeError: 'int' object is not callable

为了更好地理解什么是可调用对象read this answer in another SO post.

关于python - "TypeError ' xxx' object is not callable"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21324940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com