How to Fix TypeError:‘tuple’ object is not callable in Python?

As a Python developer working on various projects for my clients, I encountered a scenario where I faced a TypeError: ‘tuple’ object is not callable. Then, I researched this topic to solve the error, and I found several ways to accomplish this task. In this article, I will explain how to fix the TypeError: ‘ tuple’ object is not callable in Python with suitable examples and screenshots.

Fix TypeError:‘tuple’ object is not callable in Python

Let us see how to fix the TypeError:‘tuple object, which is not callable in Python, along with causes and solutions.

Read How to Use Python Type Hint Tuples for More Robust Code?

1. Incorrect Access to Tuple Elements

Cause: Use parentheses () instead of square brackets [] to access elements, making Python interpret it as a function call.

Example:

# Defining a tuple of U.S. cities
cities = ('New York', 'Los Angeles', 'Chicago')

# Attempting to access the first element with parentheses
print(cities(0))

Error Message:

TypeError: 'tuple' object is not callable

You can see the output in the screenshot below.

TypeError tuple object is not callable in Python

Solution: Use square brackets to access tuple elements.

Corrected Example:

# Accessing the first element correctly
print(cities[0])

Output:

New York

You can see the output in the screenshot below.

Fix TypeError tuple object is not callable in Python

Check out How to Sort a List of Tuples by the Second Element in Python?

2. Name a Variable ‘tuple’

Cause: Assign a variable the name tuple overrides Python’s built-in function tuple().

Example:

# Assigning a tuple to the variable named 'tuple'
tuple = ('apple', 'banana', 'cherry')

# Attempting to use the tuple() function
fruits = tuple(['orange', 'grape'])

Error Message:

TypeError: 'tuple' object is not callable

You can see the output in the screenshot below.

How to Fix TypeError tuple object is not callable in Python

Solution: Avoid naming variables with names of built-in functions.

Corrected Example:

# Using a different variable name
my_tuple = ('apple', 'banana', 'cherry')

# Now the tuple() function can be used correctly
fruits = tuple(['orange', 'grape'])
print(fruits)

Output:

('orange', 'grape')

You can see the output in the screenshot below.

TypeError tuple object is not callable in Python solution

Read How to Fix the IndexError tuple index out of range Error in Python?

3. Missing Commas Between Tuples

Cause: When creating a list of tuples, omitting commas between them results in a single, improperly formed tuple.

Example:

# Attempting to create a list of state-capital pairs
state_capitals = [
('California', 'Sacramento')
('Texas', 'Austin')
('Florida', 'Tallahassee')
]

Error Message:

TypeError: 'tuple' object is not callable

Solution: Ensure each tuple is separated by a comma.

Corrected Example:

# Correctly creating a list of tuples
state_capitals = [
('California', 'Sacramento'),
('Texas', 'Austin'),
('Florida', 'Tallahassee')
]

Check out How to Create a Tuple from the List in Python?

4. Attempt to Call a Tuple as a Function

Cause: Using parentheses after a tuple variable name makes Python attempt to call it as a function.

Example:

# Defining a tuple of numbers
numbers = (1, 2, 3)

# Attempting to call the tuple as if it were a function
result = numbers()

Error Message:

TypeError: 'tuple' object is not callable

Solution: Remove the parentheses to avoid calling the tuple.

Corrected Example:

# Accessing the tuple without calling it
print(numbers) # Output: (1, 2, 3)

By understanding these common scenarios, you can prevent and resolve the TypeError: 'tuple' object is not callable in your Python code.

Check out How to Find the Length of a Tuple in Python?

Conclusion

In this article, I helped you to understand how to fix the TypeError:’tuple’ object is not callable in Python. I explained the causes and solution to incorrect access to tuple elements, naming a variable ‘tuple’, missing commas between tuples, and attempting to call a tuple as a function.

You may read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.