Python TypeError: ‘float’ object is not callable
The TypeError: ‘float’ object is not callable error occurs if you call floating-point value as a function or if an arithmetic operator is missed while performing the calculations or the reserved keywords are declared as variables and used as functions,
In this tutorial, we will learn what float object is is not callable error means and how to resolve this TypeError in your program with examples.
What is TypeError: the ‘float’ object is not callable?
There are two main scenarios where developers get this TypeError is:
- When you try to call the reserved keywords as a function
- Missing an Arithmetic operator while performing the calculation
Scenario 1: When you try to call the reserved keywords as a function
Using the reserved keywords as variables and calling them as functions are developers’ most common mistakes when they are new to Python. Let’s take a simple example to reproduce this issue.
Output
If you look at the above code, we have declared the sum as a variable and stored a floating-point value. However, in Python, the sum() is a reserved keyword and a built-in method that adds the items of an iterable and returns the sum.
Since we have declared sum as a variable and used it as a function to add all the items in the list, Python will throw TypeError.
Solution
We can fix this error by renaming the sum variable to total_price , as shown below.
Output
Scenario 2: Missing an Arithmetic operator while performing the calculation
While performing mathematical calculations, if you miss an arithmetic operator within your code, it leads to TypeError: ‘float’ object is not callable error.
Let us take a simple example to calculate the tax for the order. In order to get the tax value, we need to multiply total_value*(tax_percentage/100) .
Output
We have missed out on the multiplication operator while calculating the tax value in our code, leading to TypeError by the Python interpreter.
Solution
We can fix this issue by adding a multiplication (*) operator to our code, as shown below.
Output
Conclusion
The TypeError: ‘float’ object is not callable error raised when you try to call the reserved keywords as a function or miss an arithmetic operator while performing mathematical calculations.
- Use descriptive and unique variable names.
- Never use any built-in function, modules, reserved keywords as Python variable names.
- Ensure that arithmetic operators is not missed while performing calculations.
- Do not override built-in functions like sum() , round() , and use the same methods later in your code to perform operations.

report this ad
TypeError: 'float' object is not callable
I am trying to use values from an array in the following equation:
When I run I receive the following error:
What is the cause, and how can the problem be resolved?
![]()
5 Answers 5
There is an operator missing, likely a * :
The «is not callable» occurs because the parenthesis — and lack of operator which would have switched the parenthesis into precedence operators — make Python try to call the result of -3.7 (a float) as a function, which is not allowed.
The parenthesis are also not needed in this case, the following may be sufficient/correct:
As Legolas points out, there are other things which may need to be addressed:
The problem is with -3.7(prof[x]) , which looks like a function call (note the parens). Just use a * like this -3.7*prof[x] .
![]()
You have forgotten a * between -3.7 and (prof[x]) .
Also, there seems to be missing an ( as I count 6 times ( and 7 times ) , and I think (math.e, (0/2.25)) is missing a function call (probably math.pow , but thats just a wild guess).
While this may not be an answer to this question in particular, another reason you could get this error is if you have defined "range" as a variable.
The solution would be to rename your variable to a synonym (period) or append something to it (range1, range_a)
The question has been answered but for others, the reason for the same error might be highly possible due to the following reason: Sometimes, when you use a variable name same as one of the inbuilt functions and when you try to call that inbuilt function later on, its gonna give you a type error. For example, somewhere in your code you define a variable as:
Maybe to use it as an accumulator variable in global dataframe. Now, later when you’re defining a function in which you want to call the inbuilt function sum() , its gonna give an type error as you have over-written an in-built function name. That’s why, you should avoid the use in-built function names like str, range, sum, etc.. as one of the variable names in your code.
How to fix “TypeError: ‘float’ object is not callable” in Python
✋ Update: This post was originally published on my blog decodingweb.dev, where you can read the latest version for a user experience.
The “TypeError: ‘float’ object is not callable” error occurs when you try to call a floating-point number ( float object) as if it was a function!
Here’s what the error looks like:
Exit fullscreen mode
Calling a floating-point number as if it’s a callable isn’t what you’d do on purpose, though. It usually happens due to a wrong syntax or overriding a function name with a floating-point number.
Let’s explore the common causes and their solutions.
How to fix TypeError: ‘float’ object is not callable?
This TypeError happens under various scenarios:
- Declaring a variable with a name that’s also the name of a function
- Calling a method that’s also the name of a property
- Calling a method decorated with @property
- Missing a mathematical operator after a floating-point number
Declaring a variable with a name that’s also the name of a function: A Python function is an object like any other built-in object, such as int , float , dict , list , etc.
All built-in functions are defined in the builtins module and assigned a global name for easier access. For instance, sum() refers to the __builtins__.sum() function.
That said, overriding a function (accidentally or on purpose) with a floating-point number is technically possible.
For instance, if you define a variable named sum and assign it to the value of 88.6 , it’ll no longer point to __builtins__.sum() .
Exit fullscreen mode
If you run the above code, Python will complain with a «TypeError: ‘float’ object is not callable» error because 88.6 (the new value of sum ) isn’t callable.
You have two ways to fix the issue:
- Rename the variable sum
- Explicitly access the sum function from the builtins module ( __bultins__.sum )
The second approach isn’t recommended unless you’re developing a module. For instance, if you want to implement an open() function that wraps the built-in open() :
Exit fullscreen mode
In almost every other case, you should always avoid naming your variables as existing functions and methods. But if you’ve done so, renaming the variable would solve the issue.
So the above example could be fixed like this:
Exit fullscreen mode
Here’s another example with the built-in max() function:
Exit fullscreen mode
And to fix it, we rename the max variable name to max_value :
Exit fullscreen mode
Another common reason is accidentally overriding the range() function with a floating-point value before using it in a for loop:
Exit fullscreen mode
To fix it, we rename the range variable:
Exit fullscreen mode
⚠️ Long story short, you should never use a function name (built-in or user-defined) for your variables!
Overriding functions (and calling them later on) is the most common cause of this type error. It’s similar to calling integer numbers as if they’re callables.
Now, let’s get to the less common mistakes that lead to this error.
Calling a method that’s also the name of a property: When you define a property in a class constructor, any further declarations of the same name (e.g., methods) will be ignored.
Exit fullscreen mode
In the above example, since we have a property named price , the method price() is ignored. As a result, any reference to the price will return the property price . Obviously, calling price() is like calling 49.5() , which raises the type error.
To fix this TypeError, we need to change the method name:
Exit fullscreen mode
Calling a method decorated with @property decorator: The @property decorator turns a method into a “getter” for a read-only attribute of the same name.
Exit fullscreen mode
You need to access the getter method without the parentheses:
Exit fullscreen mode
Missing a mathematical operator after a float variable: In algebra, we can remove the multiplication operator to avoid ambiguity in our expressions. For instance, a × b , can be ab , or a × (b + c) can become a(b + c) .
But not in Python!
In the above example, if you remove the multiplication operator in a * (b + c) , Python’s interpreter would consider it a function call! And since the value of a is numeric (a floating-point number in this case), it’ll raise the error.
So if you have something like this in your code:
Exit fullscreen mode
You’d have to change it like so:
Exit fullscreen mode
Alright, I think it does it! I hope this quick guide helped you fix your problem.
How to Solve Python TypeError: ‘float’ object is not callable
TypeError: ‘float’ object is not callable
What is a TypeError?
TypeError occurs in Python when you perform an illegal operation for a specific data type.
What Does Callable Mean?
Calling a function means the Python interpreter executes the code inside the function. In Python, we can only call functions. We can call functions by specifying the name of the function we want to use followed by a set of parentheses, for example, function_name() . Let’s look at an example of a working function that returns a string.
We declare a function called simple_function in the code , which prints a string. We can then call the function, and the Python interpreter executes the code inside simple_function() .
If we try to call a floating-point number, we will raise the TypeError:
Example #1
Let’s look at an example to prove the sum of squares formula for two values. We define two variables with floating-point values, calculate the left-hand side and right-hand side of the formula, and then print if they are equal.
Let’s run the code to see what happens:
The error occurs because we do not have the multiplication operator * between the two (a + b) terms. The Python interpreter sees this as a call to (a + b) with parameters (a + b).
Solution
We need to put a multiplication operator between the two (a + b) terms to solve the error. Let’s look at the revised code:
Let’s run the code to see what happens:
We get a True statement, proving that the sum of squares formula works.
Example #2
Let’s look at an example of converting a weight value in kilograms to pounds. We give the conversion value the name “ float ” and then take the input from the user, convert it to a floating-point number then multiply it by the conversion value.
Let’s run the code to see what happens:
The error occurs because we assigned the value 2.205 to “ float “. Then we tried to call the built-in float() method, but float is now a floating-point number.
Solution
We can name our conversion variable something more meaningful to solve this error. Let’s call it “conversion”. Then we can call the float() method safely. Let’s look at the revised code:
Let’s run the code to get the result:
The program takes the input from the user in kilograms, multiplies it by the conversion value and returns the converted value to the console.
Summary
Congratulations on reading to the end of this tutorial! To summarize, TypeError ‘float’ object is not callable occurs when you try to call a float as if it were a function. To solve this error, ensure any mathematical operations you use have all operators in place. If you multiply values, there needs to be a multiplication operator between the terms. Ensure that you name your float objects after their purpose in the program and not as “float”.
To learn more about Python, specifically for data science and machine learning, go to the online courses page on Python.