‘float’ object is not callable – Python TypeError


Python throws the error, ‘float’ object is not callable when you try to call a float value as function. This happens when you use reserved keywords as your variable name or override library functions with float variables.

For example, round() is the function which is used to round the number to the nearest integer. Now if we declare a float variable with name round, then within the scope of that variable, we won’t be able to use round() function. Check this code –

round = 5.0;
round(5 * 3 / 2);
// TypeError: 'float' object is not callable.

The above code will throw TypeError: ‘float’ object is not callable.

The solution to this problem is to keep a close eye on your variable names. Avoid using very common names which could match the general functions. Have a little understanding of Math functions and reserved keywords.

Reserved Keywords

You can’t use these keywords as your variable names. So if you try to use them, you will get the error.

and del from not
while as elif global
or with assert else
if pass yield break
except import print class
exec in raise continue
finally is return def
for lambda try

    Tweet this to help others

Live Demo

Demo might not work in private window (Incognito)

Sign Up for Our Newsletters

Get only the best articles delivered to your mail

You May Also Like

Convert list to string in Python

Table of Contents Hide Joining with delimiterJoining integer itemsUsing map() functionUsing lambda functionUsing LoopsLive DemoRelated Posts: Python provides join() function which could be used to convert list to string. If…
View Post
python run bash script in background

python run bash script in background

Table of Contents Hide IntroductionTerminating background script after a timeoutHow to check if process is still running or terminated?How to get output from process?ConclusionLive DemoRelated Posts: Python subprocess library is…
View Post