Use cases for del

Reinhold Birkenfeld reinhold-birkenfeld-nospam at wolke7.net
Sun Jul 10 10:49:36 CEST 2005


Ron Adam wrote:

>>     >>> 'abc' is 'abcd'[:3]
>>     False
> 
> Well of course it will be false... your testing two different strings! 
> And the resulting slice creates a third.
>
> Try:
> 
> ABC = 'abc'
> 
> value = ABC
> if value is ABC:   # Test if it is the same object
>     pass

That's not going to buy you any time above the "is None", because identity-
testing has nothing to do with the type of the object.

Additionally, using "is" with immutable objects is horrible.

Reinhold



More information about the Python-list mailing list