id( ) function question

Laszlo Nagy gandalf at shopzeus.com
Wed Oct 14 22:37:27 CEST 2009


> Andre Engels schrieb:
>   
>> What is going on is that a few objects that are often used, in
>> particular the small (how small is small depends on the
>> implementation) integers, are 'preloaded'. When one of these is then
>> referred to, a new object is not created, but the pre-defined object
>> is used. 10 is apparently a preloaded constant in your implementation,
>> 1e10 is not.
>>
>> As far as I know, only None is _guaranteed_ to be such a preloaded
>> object, so one should not rely on it in implementations.
>>     
>
> None, True, False, NotImplemented are guaranteed to be singletons, all
> builtin types and exceptions can be considered as singletons, too.
>   
I thought that different mutable objects always have different ids. If 
this is not true, then what the id() function is used for? What useful 
thing can we do with it?

Thanks,

L




More information about the Python-list mailing list