What does “TypeError 'xxx' object is not callable” means?

前端 未结 5 1436
梦谈多话
梦谈多话 2020-12-01 02:43

As a starting developer in Python I\'ve seen this error message many times appearing in my console but I don\'t fully understand what does it means.

Could anyone tel

5条回答
  •  星月不相逢
    2020-12-01 03:26

    The action occurs when you attempt to call an object which is not a function, as with (). For instance, this will produce the error:

    >>> a = 5
    >>> a()
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: 'int' object is not callable
    

    Class instances can also be called if they define a method __call__

    One common mistake that causes this error is trying to look up a list or dictionary element, but using parentheses instead of square brackets, i.e. (0) instead of [0]

提交回复
热议问题