How to Fix: TypeError: ‘float’ object is not callable

3D illustration of a robot trying to use a metal sphere as a walkie-talkie, representing the float object is not callable error.

This error is a direct cousin to TypeError: ‘int’ object is not callable. The TypeError float not callable message means: “You are trying to use a float (a decimal number) as if it were a function.”

A “callable” is anything you can put parentheses () after, like print() or my_function(). A float, like 3.14, is just data.

The Cause

The most common cause is overwriting a function name with a variable that holds a float.

Problem Code: Let’s say you’re calculating an average, but you re-use the round function name.

# 'round' is a built-in function
my_numbers = [1.234, 5.678]

# 1. You calculate a value and store it...
# ... but you accidentally name it 'round'!
round = round(my_numbers[0], 1) # 'round' is now the FLOAT 1.2

# 2. You try to use the *real* round() function again
new_val = round(my_numbers[1], 1)
# CRASH! TypeError: 'float' object (the number 1.2) is not callable

The Fix: Don’t Overwrite Built-in Names

NEVER use built-in function or type names as your variable names.

my_numbers = [1.234, 5.678]

# Use a safe variable name
rounded_val = round(my_numbers[0], 1)

# The 'round' function is still safe!
new_val = round(my_numbers[1], 1)
print(new_val)

Other built-in names to avoid: sum, str, int, list, dict, float, max, min.

Similar Posts

Leave a Reply