How often have you used the function range()
in Python? It’s often something you use early on as you learn about the for
loop…
But… did you know it’s not really a function, after all?!
Have a look at the docs or use help()
to check…
range
is a class. And therefore range()
creates an instance of the class as is always the case with a class.
So, my question is: “Does it matter?”
Technically, it does. A function is not a class – they’re different things
But in practice, what matters is how it behaves and not what it is!
This is a key principle in Python when thinking about data types. What they do and how they behave matters more that what they are!
So you can use range()
like a function, even though it’s not!
@andrewhoyer it “behaves” like a function. In many ways, that’s all that matters!
@s_gruppetta Thanks for sharing! I think this is what APIs of any kind are for - serve the purpose and be easy to understand: no matter if that's a built-in library, some additional package or even REST/SOAP. Clearly, a good example that we should focus on building a good interfaces first.