TypeError: 'list' object is not callable in Python 3.8.2
Dung Do Tien
Aug 28 2021
142
I am a student and I self to learn about Python 3.8.2.
I have an array of animals and I want to change all of the items from lowercase to uppercase. Like below:
animals = ["elephent", "dog", "cat", "duck", "tiger"]
for n in range(len(animals)):
animals[n] = animals(n).upper()
print(animals(n))
print(animals)
But I get an exception TypeError: 'list' object is not callable.
Traceback (most recent call last):
File "main.py", line 4, in <module>
animals[n] = animals(n).upper()
TypeError: 'list' object is not callable
Anybody can explain to me why? and how to resolve it?
Thanks for the help.
Have 1 answer(s) found.
-
U0
Unnop Niratiam Aug 28 2021
Oh, I think this is a basic error. To access and get or set an item of an array you have to use
[]
not()
.See code below:
animals = ["elephent", "dog", "cat", "duck", "tiger"] for n in range(len(animals)): animals[n] = animals[n].upper() print(animals[n])
#OUTPUT
ELEPHENT DOG CAT DUCK TIGER
I hope it is useful to you.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.