Author -  Sai gowtham

How to solve list object is not callable error in Python

In this tutorial, we will learn how to solve the TypeError: ‘list’ object is not callable in Python.

This error occurs for one of the following reasons:

  1. If you try to use a list keyword as a variable name.

  2. Using the parenthesis () instead of square brackets [] to access the elements from the list at a specific index.

Here is an example of how the error occurs:

price_list = [10, 20, 30]

# using parenthesis for accessing data
print(price_list(1))

Output:

Traceback (most recent call last):
  File "main.py", line 13, in <module>
    print(price_list(1))
TypeError: 'list' object is not callable

In the above example , we are getting the error because we are using the () to access the data from a list instead of [] square brackets.

To solve the “TypeError: ‘list’ object is not callable” error, use the square brackets [] syntax to access the elements from a list.

Here is an example:

price_list = [10, 20, 30]

print(price_list[1]) # 20
print(price_list[2]) # 30

Note: The list is an object data type in Python.

Another common cause of the error is using the built-in list() function as a variable name in Python.

Here is an example:

# overiding the built-in list() function
list = [10, 20, 30]

# creating a list using list() function
fruits_list = list(['apple', 'banana', 'cherry'])
print(fruits_list)

Output:

Traceback (most recent call last):
  File "main.py", line 14, in <module>
    fruits_list = list(['apple', 'banana', 'cherry'])
TypeError: 'list' object is not callable

To Solve the error, change the variable name to someother and re-run the code.

# not overiding the built-in list() function
price_list = [10, 20, 30]

fruits_list = list(['apple', 'banana', 'cherry'])
print(fruits_list)

and do not use the list keyword as a variable name because it is reserved for list() function in python

Conclusion

The “list” object is not callable error occurs, when we try to call a list object as a python function using the parenthesis (). To solve the error, use the square brackets [] to access the data at a specific index eg: price_list[1] and do not use the list built-in keyword as a variable name because it is reserved for list() function in python.

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY