Is An Element of a Sequence an Object?
Thomas Jollans
tjol at tjol.eu
Mon Jun 5 05:30:43 EDT 2017
On 05/06/17 09:38, Jussi Piitulainen wrote:
> Peter Otten writes:
>
>> Thomas Jollans wrote:
>>> Also:
>>>
>>>>>> s[0] is s[0][0][0][0][0][0][0]
>>> True
>>>>>>
>>
>> However, this is an implementation detail:
>>
>>>>> def is_cached(c):
>> ... return c[0] is c[0][0]
>> ...
>
> I think this works the same, and looks more dramatic to me:
>
> ... return c[0] is c[0]
I love this.
What I thought was going on was that single-character strings return
self on [0], as they do on full-length slices.
>>> c = 'δ'
>>> c[0] is c
False
>>> c[:] is c
True
>>> c[0:1] is c
True
>>>
I wonder why they don't do this...
>
>>>>> is_cached(chr(255))
>> True
>>>>> is_cached(chr(256))
>> False
>
> Also same thing, as far as I can see:
>
>>>> s = "\u00ff\u0100" ; (s[0] is s[0], s[1] is s[1])
> (True, False)
>
More information about the Python-list
mailing list