A Callable Float? Fun and Creativity in Python

Among the built-in data types in Python, we have a number of types representing numbers, the most important being int and float. As everything in Python, their instances are objects; and as objects, they have their own attributes and methods. For example, this is what instances of the float type offer:

As you see, float numbers offer many different methods to use. What they do not offer is a .__call__() method, which means you cannot call them.

Have you ever pondered why we cannot call a floating-point number the way you can call a function? Look:

>>> i = 10.0012
>>> i()
Traceback (most recent call last):
    ...
TypeError: 'float' object is not callable

It does not work. And why does it not work?!

To be honest… I’ve never pondered why floats are not callable — but it makes perfect sense to me. Why would they? What for? Do you see any particular reason for them to be? I don’t.

Visit Now