13 AnswersNew Answer
Ore... I had similar questions about this a while back and was disappointed by the lack of clarification in the official documentation. I decided to review the C and Python source code directly and made the following assessment. IIRC, these built-in functions are special functions that map directly to C functions. Therefore, technically, these are the most fundamental functions for which all other functions and classes in Python are built on. For this reason, built-in C functions, like str(), int(), type(), etc, build objects as if they're class constructors and will resolve as <class 'type'>. While these built-in C functions might seem more like Python class constructors, perhaps it's the other way around. That is, I speculate the interface for creating objects in Python is modeled after these built-in C functions. Makes you wonder... 😉 Also, you might be interested in my version of your code, which I created some time ago on my local computer: https://code.sololearn.com/c26xp4s2z6zk/
Why does the documentation refer to them as functions when they are, in fact, constructors? I see it was explained clearly down the page but the title "built-in functions" is misleading. https://docs.python.org/3/library/functions.html
Slick If you look closely, you will notice that some of the built-ins where prefixed with 'class' e.g ''' class bool([x]) ''' These are constructors and have a type of <class "type"> Somewhere down the page you will find this ''' class list([iterable]) Rather than being a function, list is actually a mutable sequence type, as documented in Lists and Sequence Types — list, tuple, range. ''' Conclusion - not all the built ins are functions. Which explains our previous findings. I just wish the documentation made this more obvious from the start.
I think type is the class of classes.
Ore Yes. isinstance(str, type) ---> True
David Carroll Thanks for the answer. I will check the code when I have time.
makes sense since python is so uppity about EVERYTHING is a class (or part of one) funny find though.
Slick I think you meant that everything is an object. Yes. That is true but functions are also object. So `type` would still be an object if it was a function.
I just checked as well that is a bit weird. Then i tried type checking "all" and it comes out as what's expected (function or built in method)! I think it may be how each is made induvidually
Seb TheS I don't understand. Are you saying every class is an instance of `type`? 😲
Seb TheS It's all too confusing for me 🧐