Skip to main content

How to Resolve Python "TypeError: 'int' object is not callable"

The TypeError: 'int' object is not callable is a common Python error that arises when you try to use an integer value as if it were a function by appending parentheses () to it. Integers represent numerical data and can not be executed or "called" like functions or methods.

This guide explains the various scenarios that lead to this error and provides clear solutions for each.

Understanding the Error: Callable vs. Non-Callable Objects

In Python, parentheses () following a name indicate a call operation,i.e. you're asking Python to execute the code associated with that name (e.g., run a function, call a method, instantiate a class). Objects that can be called are known as "callables". Integers (int), like other simple data types such as strings (str) or booleans (bool), are not callable. They hold data, but they don't represent executable code blocks themselves. Trying to call a non-callable object like an integer results in a TypeError.

my_number = 42
print(type(my_number)) # Output: <class 'int'>

try:
# ⛔️ TypeError: 'int' object is not callable
# Trying to "call" the integer 42
my_number()
except TypeError as e:
print(e)

Cause 1: Accidentally Calling an Integer Variable

The simplest cause is having a variable that holds an integer and mistakenly adding parentheses after it, maybe intending to print it or use it in another operation.

count = 10

# Error Scenario
try:
# ⛔️ TypeError: 'int' object is not callable
# Added parentheses to the integer variable 'count'
print(count())
except TypeError as e:
print(e)

# Solution: Remove the parentheses
# ✅ Access the integer value directly
print(count) # Output: 10

Cause 2: Missing Mathematical Operator

This error can uniquely occur with numbers when you implicitly try to multiply by juxtaposition (like in mathematical notation 2x) but forget the actual multiplication operator (*). Python interprets number(expression) as attempting to call number.

# Error Scenario
try:
# ⛔️ TypeError: 'int' object is not callable
# Missing '*' between 2 and the parenthesis
result = 2 (5 + 3)
print(result)
except TypeError as e:
print(e) # Output: 'int' object is not callable

# Solution: Add the missing operator
# ✅ Add the explicit multiplication operator '*'
result_multiply = 2 * (5 + 3)
print(f"Multiplication: {result_multiply}") # Output: Multiplication: 16

# Other operators also work, if intended
result_add = 2 + (5 + 3)
print(f"Addition: {result_add}") # Output: Addition: 10

Ensure all mathematical operations have explicit operators (+, -, *, /, etc.).

Cause 3: Variable Name Clashing with Function Name

Assigning an integer to a variable that has the same name as a previously defined function will hide the function. Subsequent attempts to call the function by that name will instead try (and fail) to call the integer value stored in the variable.

def calculate_score():
"""Calculates a score."""
print("Original calculate_score function...")
return 100

# Function works initially
score = calculate_score()
print(f"Initial score: {score}")

# --- Later in the code ---
# ⚠️ Variable assigned the same name as the function!
calculate_score = 50 # Now 'calculate_score' refers to the integer 50

# Error Scenario
try:
# ⛔️ TypeError: 'int' object is not callable
# This tries to call the integer 50
new_score = calculate_score()
print(new_score)
except TypeError as e:
print(f"Error: {e}")

# Solution: Rename the variable or the function
def calculate_score_func(): # Renamed function
print("Original calculate_score_func...")
return 100

current_score_value = 50 # Use a different variable name

# ✅ Calling the renamed function works
new_score_fixed = calculate_score_func()
print(f"Fixed call result: {new_score_fixed}") # Output: 100
note

Use distinct names for your variables and functions.

Cause 4: Shadowing the Built-in int Type

If you name a variable int, you override Python's built-in int() type constructor. Later attempts to use int() (e.g., to convert a string to an integer) will mistakenly try to call your integer variable.

# Error Scenario
# ⚠️ Assigning an integer to the name 'int', hiding the built-in type
int = 123
print(f"The variable 'int' now holds: {int}")

try:
# ⛔️ TypeError: 'int' object is not callable
# This tries to call the variable int = 123
number_from_string = int("456")
print(number_from_string)
except TypeError as e:
print(e)

# Solution: Use a different variable name
# ✅ Avoid using built-in names for variables
my_integer_variable = 123

# ✅ Now int() refers to the built-in type constructor again
number_from_string_fixed = int("456") # Correctly converts string '456' to integer 456
print(f"Using built-in int(): {number_from_string_fixed}") # Output: 456
note

Never shadow built-in function or type names. Restart your session/kernel if you do this interactively.

Cause 5: Class Attribute Name Clashing with Method Name

Within a class, an instance attribute and a method sharing the same name can lead to this error if the attribute holds an integer. Accessing the name on an instance typically retrieves the attribute, hiding the method.

class Counter:
def __init__(self, initial_value=0):
# Instance attribute named 'value'
self.value = initial_value # Holds an integer

# Method with the *same name* as the attribute
def value(self):
print("Method 'value' called!") # This is hard to reach
return self.value * 10 # Example method logic

# Error Scenario
counter_instance = Counter(5)
print(f"Attribute value: {counter_instance.value}") # Accesses the integer attribute -> 5

try:
# ⛔️ TypeError: 'int' object is not callable
# counter_instance.value resolves to the attribute (5). Calling 5() fails.
result = counter_instance.value()
print(result)
except TypeError as e:
print(f"Error: {e}")


# Solution: Rename the method or attribute
class CounterFixed:
def __init__(self, initial_value=0):
# Use a different attribute name
self._value = initial_value # Convention: prefix with _

# Or rename the method
def get_value(self):
print("Method 'get_value' called!")
return self._value

counter_fixed = CounterFixed(5)

# ✅ Call the distinct method name
result_fixed = counter_fixed.get_value()
print(f"Fixed call result: {result_fixed}") # Output: 5
note

Use distinct names for attributes and methods.

Cause 6: Calling a Function That Returns an Integer Twice

If a function returns an integer, calling it once works correctly. Adding a second set of parentheses attempts to call the integer that was returned by the first call.

def get_item_count():
print("Getting count...")
return 42 # Returns an integer

# Error Scenario
try:
# ⛔️ TypeError: 'int' object is not callable
# get_item_count() returns 42. The second () tries to call 42().
count = get_item_count()()
print(count)
except TypeError as e:
print(f"Error: {e}")

# Solution: Call the function only once
# ✅ Get the integer by calling the function once
count = get_item_count()
print(f"Count: {count}") # Output: 42
note

Remove the extra parentheses.

Debugging Tip: Check Variable Types

When this error occurs, the quickest way to confirm the cause is often to check the type of the object you are trying to call right before the error line:

variable_causing_error = ... # The name involved in the error

print(f"Type before call: {type(variable_causing_error)}")
# Attempt the call that raises the error
try:
variable_causing_error()
except TypeError as e:
print(f"Error confirms type issue: {e}")

If the type is <class 'int'>, you've found the immediate problem and need to apply the relevant solution from above.

Conclusion

The TypeError: 'int' object is not callable occurs when you incorrectly use call parentheses () on an integer value. Key solutions include:

  1. Removing parentheses from integer variables when just accessing their value.
  2. Adding missing mathematical operators (like *) if multiplication by juxtaposition was intended.
  3. Using distinct names for variables and functions/methods/types to prevent shadowing.
  4. Calling functions that return integers only once.

By understanding that integers are data, not executable functions, and by being mindful of potential name clashes, you can easily avoid and fix this common TypeError.