‘tuple’ object is not callable – Python Error

Total
0
Shares

Python throws the error, ‘tuple’ object is not callable, when you forget to separate members using comma in single or multidimensional tuples.

Consider this example –

myTuple = (
    ("Captain America", "Shield")
    ("Ironman", "Suit")
    ("Thor", "Mjolnir")
    ("Hawkeye", "Bow-arrows")
    ("Spiderman", "Web Shooters")
)

print(myTuple)
# Error: 'tuple' object is not callable

This code will throw the tuple object not callable error because although we put commas in 2nd dimensional elements like ("Captain America", "Shield") we forgot to put one in 1st dimension like ("Captain America", "Shield") , ("Ironman", "Suit").

The correct way to write this code is –

myTuple = (
    ("Captain America", "Shield"),
    ("Ironman", "Suit"),
    ("Thor", "Mjolnir"),
    ("Hawkeye", "Bow-arrows"),
    ("Spiderman", "Web Shooters")
)

print(myTuple)

    Tweet this to help others

Live Demo

Demo might not work in private window (incognito)

Sign Up for Our Newsletters

Get only the best articles delivered to your mail

You May Also Like