From the course: Advanced Python: Object-Oriented Programming

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Callable

Callable

- [Instructor] Let's look at callables. When you want to check if something can be called as a function, the built-in function is called callable, not isfunc or function. And this is because you can implement the dunder call method and your types also can be used as function. Let's see an example. So let's say we want to normalize the value. So we do value times 0.9 and let's run this cell and I'm going to hide the files. Now if you look at normalize, we do dir of normalize and Shift and Enter, we're going to see all the attributes it has and including dunder call. So even a function has a dunder call for it. More than that, if you want to look at dis assembly from dis import dis, and then dis(normalize), we're going to see the virtual machine code and we see that it does LOAD_FAST of the value LOAD_CONST of 0.9, then binary operation of multiplication and return value. The normalize itself, normalize.__, has a dunder code, which is the binary code that Python holds. And if you do the…

Contents