__class__ for 2.2 types

Jim Dennis jimd at vega.starshine.org
Sun Feb 17 13:43:45 EST 2002


In article <a3upaq$1arn1e$1 at ID-59885.news.dfncis.de>, Thomas Heller wrote:

>"Larry" <wrbt at email.com> wrote in message news:2ec1bc1c.0202071240.44185531 at posting.google.com...
>> 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'>?

> int is the *type* of an integer, not an integer itself.

> See:
>>>> list.__class__
> <type 'type'>
>>>> 2.__class__
>  File "<string>", line 1
>    2.__class__
              ^
>SyntaxError: invalid syntax
>>>> 2 . __class__
><type 'int'>

>Thomas

 That's an interesting "gotchya"  I understand why 2.__class__ is a
 syntax error (ambiguous with a float: 2.0 etc).  But I'm surprised 
 that 2 . __class__ works; the spaces seem unnatural here. 

 (2).__class__ makes sense because it uses parentheses in a natural 
 way (to disambiguate precedence and/or parsing in an expression). 







More information about the Python-list mailing list