The definition of an object in Python

Max M maxm at mxm.dk
Sun Jul 13 19:51:35 CEST 2003


Avi Kak wrote:

>   But when I do the following
> 
>       mystring = 'hello'
> 
>       print mystring.id()
> 
>       print mystring.type()
> 
>   Python complains that mystring does not possess the attributes
>   id and type.


mystring = 'hello'

print id(mystring)

print type(mystring)

 >>> 8985424
 >>> <type 'string'>


id and type are built in functions. Not methods on objects.

Wich imho is a good thing. This means that you can have methods on 
objects called id and type, without loosing the ablity to use these 
functions.


regards Max N





More information about the Python-list mailing list