. Advertisement .
. Advertisement .
This error is a common error in Python:
TypeError: 'list' object is not callable
Look at the TypeError error type. It informs you that the method you are attempting to alter a value is not supported by the type of data in which it is stored. You can see from the error message that you are attempting to call a Python list object. This error indicates that you handle it more like a function than a list.
Here is the code:
fruit = "Apple" list = list(fruit) print(list)
In the above program, this error occurs when you try to convert that into a list by creating a list.
Here is a suggestion for you to solve the error “TypeError: ‘list’ object is not callable”:
- You can solve the error by using the built-in list of names as the variable name
fruit = "Apple" fruit_list = list(fruit) print(fruit_list)
- Alternatively, using square brackets to access items in a list is not a bad solution. You can use curly brackets to call functions in Python. Because you’re using curly brackets to access list elements, your code has a difficulty because you’re trying to call a list as a function.
Use curly brackets in your code to retrieve a list item from two different locations:
for n in range(len(names)): names[n] = names(n).upper() print(names(n))
To utilize square brackets, you must reverse the names(n) code:
for n in range(len(names)): names[n] = names[n].upper() print(names[n])
This instructs Python that you wish to retrieve the element in the list “names” at index position “n”.
Run your code using the relevant modifications you just talked about:
PETER GEOFFREY DAKOTA WILLIAMS REBECCA LEE ['PETER GEOFFREY', 'DAKOTA WILLIAMS', 'REBECCA LEE']
This time, the response is adequate. All names are written in capital letters. The name in capital letters takes the place of the name in sentence case. The console is then printed with each name. You print out a list of all the names in “names” after your program is finished to make sure they have been updated in your list.
# 'list' object is not callable # Problem names = ["Peter Geoffrey", "Dakota Williams", "Rebecca Lee"] for n in range(len(names)): names[n] = names(n).upper() print(names(n)) print(names) # Solution for n in range(len(names)): names[n] = names(n).upper() print(names(n))