Solved – TypeError: ‘list’ object is not callable in Python

TypeError: ‘list’ object is not callable in Python is an error that occurs when a conflict happens between your chosen name and a build-in name.

In this article I am going to try to explain the source of this error and how to avoid it and solve it, I am also going to include other possible solutions that worked for other developers.

Explaining The Error : TypeError: ‘list’ object is not callable in Python

Let us try and replicate this error step by step.

Let us start with this line of code

                                                                       #
example = list('ronaldo')
                                                                       #

If you pay attention, you should notice that we have referred to a build-in class by using “list”

Now, let us create a variable called list referencing an instance to list

                                                                       #
list = list('rickou')
                                                                       #
                                                                       #
example = list('ronaldo')
                                                                       #

The result is the obvious error that we are trying to solve

                                                                       #
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: 'list' object is not callable
                                                                       #

Before we solve this error we need to understand it, We can not understand the issue without knowing what a built-in name is in Python.

A built-in name In Python is a name that the Python interpreter already has assigned a predefined value. 

There are more than 60 built-in names in Python.

You need to understand that Python is not going to stop you from using those built-in names.

You will only know that you should avoid them after you get a confusing error like the one above.

Let us find a solution to this error, the one that I think is better is the first solution.

Solution 1 : rename the variable “list”

Let’s create a scenario where we replicate the error.

Let us run the following code

                                                                       #
list = [1, 2, 3, 4, 5]
myrange = list(range(1, 10))

for number in list:
    if number in myrange:
        print(number, 'is between 1 and 10')
                                                                       #

After running the code above, I am going to get the error bellow :

                                                                       #
Traceback (most recent call last):
  File "python", line 2, in <module>
TypeError: 'list' object is not callable
                                                                       #

The error is caused by the offending variable list.

The fix is simple, we should rename the variable “list” in our case, the issue is easily solved as a result.

Solution 2 : Do not use round brackets instead of using square brackets when accessing an item in the list

Sometimes, you can get the same error for other reasons that we can not cover in this article.

An example to this, is when you use round brackets instead of using square brackets when accessing an item in the list, the resulting error is the same.

                                                                       #
l=[1,2,3]
                                                                       #

This is the right way to do it

                                                                       #
print(l[2])
                                                                       #

If you use round brackets like in the code bellow, you are going to get the same error.

                                                                       #
print(l(2))

So avoid using those round brackets, if this article is helpful so far, please consider donating to our blog, we have a Kofi donation button above.

The last solution

Another different scenario that can cause this error is if you have a method that returns a list to which we assigned a @property decorator.

In this particular case, if you call method() instead of method, you are going to get the same error.

Summing-up

The end, we arrived at the end of this article, I hope my article helped you solve your issue, I am sure there are at least 10 other reasons why this error occurs, I can not find them all and explain them, this is my best attempt guys, Thank you for reading, cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/