A Callable Float? Fun and Creativity in Python
<p>Among the built-in data types in Python, we have a number of types representing numbers, the most important being <code>int</code> and <code>float</code>. 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 <code>float</code> type offer:</p>
<p>As you see, <code>float</code> numbers offer many different methods to use. What they do not offer is a <code>.__call__()</code> method, which means you cannot call them.</p>
<p>Have you ever pondered why we cannot call a floating-point number the way you can call a function? Look:</p>
<pre>
>>> i = 10.0012
>>> i()
Traceback (most recent call last):
...
TypeError: 'float' object is not callable</pre>
<p>It does not work. And why does it not work?!</p>
<p>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.</p>
<p><a href="https://towardsdatascience.com/a-callable-float-fun-and-creativity-in-python-7a311ccd742d">Visit Now</a></p>