Use cases for del
Ron Adam
rrr at ronadam.com
Sun Jul 10 13:59:46 EDT 2005
Reinhold Birkenfeld wrote:
> 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.
Ok, I retested it... Not sure why I was coming up with a small
difference before. <shrug> It seemed strange to me at the time which
is part of why I asked.
My point was using strings "could" work in same context as None, (if
None acted as del), with out a performance penalty. Anyway, this is all
moot as it's an solution to a hypothetical situation that is not a good
idea.
> Additionally, using "is" with immutable objects is horrible.
Why is it "horrible"? Oh nevermind. ;-)
Cheers,
Ron
> Reinhold
More information about the Python-list
mailing list