3 ms·
> Nothing in x = d(x) necessitates that d is a function - d just has to be callable! Python being duck-typed, what's the distinction?
by lmm 9y ago
> Nothing in x = d(x) necessitates that d is a function - d just has to be callable!
Python being duck-typed, what's the distinction?
- aldanor 9y agoThe distinction is that ‘function’ is a type which you can check as in isinstance(obj, types.FunctionType)
- kzrdude 9y agoTo point out that other callable things can be used. You would not say that "classes are functions" I think, yet they are callable.
- Sohcahtoa82 9y ago"callable" essentially just means you can put a "()" after the name in the code and it works. You can "call" a class. Doing so allocates an instance of that class (Or calls the __new__ function if one is defined) and returns it, first calling the __init__ function of that class if necessary. You can also "call" an object if its class has a __call__ function defined.
- lmm 9y agoIndeed, but isn't that exactly what "quacking like a function" is?