Everything is an object in python - object class and type class

Chris Angelico rosuav at gmail.com
Mon Jun 1 21:30:34 EDT 2015


On Tue, Jun 2, 2015 at 11:15 AM, TheDoctor <dreamingforward at gmail.com> wrote:
> Let me make this clearer to you, Chris, because I don't want you to have to suck it too, like the rest of this community.
>
> A type is not an object.  You see it as one, because you are MENTALLY lexing your own code on the screen.  But python does not define a type.  It defines certain primitives, like strings and integers.  But it doesn't define what an OBJECT is.  So you and everyone else are beating around the bush trying to define something that the LANGUAGE ITSELF doesn't define.  So, don't make a claim about it.
>
> In Python 2.7 type(type) is type (not object), but isinstance(type, object) is true -- so it is ambiguous, even contradictory, in the language.
>

I'm not saying this for dreamingforward's benefit, as he clearly isn't
interested in learning, but in case the OP is confused: Checking the
type of something doesn't tell you what it isn't. The isinstance check
is true, because type is an instance of type, which is a subclass of
object, therefore type is an instance of object. Similarly, you could
check this:

>>> issubclass(type, object)
True

So you can see that a type IS an object.

ChrisA



More information about the Python-list mailing list