__class__ for 2.2 types

Philip Swartzleonard starx at pacbell.net
Fri Feb 8 05:03:31 EST 2002


Michael Chermside || Thu 07 Feb 2002 01:24:09p:

>> hi, rookie here, I was hoping someone could explain to me why this
>> happens: 
>> 
>> Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> [].__class__
>> <type 'list'>
>>>>> int.__class__
>> <type 'type'>
>> 
>> why doesn't the int one return <type 'int'>? 
>> 
>> thanks in advance
> 
> Because "int" isn't an int. "5" is.
> 
> 
>>>> [].__class__
> <type 'list'>
>>>> x = 7
>>>> x.__class__
> <type 'int'>
> 
>>>> int.__class__
> <type 'type'>
>>>> str.__class__
> <type 'type'>

You will also notice that 
>>> [].__class__.__class__
<type 'type'>
>>> x.__class__.__class__
<type 'type'>

Also, there is a type object laying in the standard builtins (along with 
object and int and all that).

>>>[].__class__.__class__ is type
1

And now, if you want to go insane:

>>>type.__class__ is type
1
>>>type.__class__.__class__ is type
1

and so on. :)


-- 
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com



More information about the Python-list mailing list