TypeError: ‘tuple’ object is not callable in Python
Dung Do Tien Aug 09 2021 186
I'm studying Python with version 3.8.2 and I wan to print all item in a tuple as below:
marks = [
("Kimmi", 72),
("chanda", 93),
("Nupur", 27)
]
for i in marks:
print("Names: " + str(i(0)))
But I get an error TypeError: ‘tuple’ object is not callable
Traceback (most recent call last):
File "main.py", line 7, in <module>
print("Names: " +str(i(0)))
TypeError: 'tuple' object is not callable
How can I resolve this error?
Have 1 answer(s) found.
- d0
dang thanh tuan Aug 09 2021
It’s simple. But, first, we have to use square brackets
[ ]
to retrieve values from our tuples. So, Let’s look at our code.marks = [ ("Kimmi", 72), ("chanda", 93), ("Nupur", 27) ] for i in marks: print("Names: " +str(i[0]))
I hope it solve for you!
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.