Throw typeerror: 'tuple' object is not callable in Python

Dung Do Tien Oct 18 2021 98

Hello you guys, I a newbie in Python and I'm also studying more about Python.

I write some line of code help me understand more about Tuple in Python. 

I also want to compare tuple and array. and find more best practice to do with tuple

My code as below:

countryData = (
    ("United State", "USA")
    ("United Kingdom", "UK")
    ("Canada", "CA")
    ("Vietname", "VN")
    ("China", "CN")
)

print(countryData)

But I get an exception throw TypeError: 'tuple' object is not callable when I run code above.

main.py:3: SyntaxWarning: 'tuple' object is not callable; perhaps you missed a comma?
  ("United State", "USA")
Traceback (most recent call last):
  File "main.py", line 3, in <module>
    ("United State", "USA")
TypeError: 'tuple' object is not callable

And I am using python 3.8.2

Anyone can explain it to me? 

How can I solve it?

Thanks for any suggestions.

Have 1 answer(s) found.
  • D

    Devx Mon Oct 18 2021

    This error throw because you created a tuple wrong syntax. You lost , comma between item in Tuple.

    See code below:

    countryData = (
        ("United State", "USA"),
        ("United Kingdom", "UK"),
        ("Canada", "CA"),
        ("Vietname", "VN"),
        ("China", "CN")
    )
    
    print(countryData)

    #Output

    (('United State', 'USA'), ('United Kingdom', 'UK'), ('Canada', 'CA'), ('Vietname', 'VN'), ('China', 'CN'))

    I hope it clear and solved issue for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close