[Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me
Alex Kleider
akleider at sonic.net
Sat Jan 16 19:23:36 EST 2016
On 2016-01-16 16:08, Alan Gauld wrote:
> On 16/01/16 23:56, Alan Gauld wrote:
>> On 16/01/16 22:39, boB Stepp wrote:
>>
>>> So in this model of understanding negative list indexing, should it
>>> be:
>>>
>>> mylist = [ 100, 200, 300, 400, 500 ]
>>> ^ ^ ^ ^ ^ ^
>>> -5 -4 -3 -2 -1 ?
>>>
>>> Well, it has to be this; otherwise, the off-by-one error exist. This
>>> also continues to explain why
>>>
>>> mylist.insert(-1, x)
>>>
>>> inserts x *before* 500. But in this model, what should go in the
>>> place of "?"?
>>
>> -0
>>
alex at x301:~$ python3
Python 3.4.3 (default, Oct 14 2015, 20:33:09)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> mylist = [1, 2, 3, 4, 5]
>>> mylist[0:None]
[1, 2, 3, 4, 5]
>>> mylist[0:-0]
[]
>>> -0
0
>>>
It appears that None provides a surrogate for -0 which itself evaluates
to 0.
>
> I should have added a :-/ to that in case it wasn't obvious...
It wasn't to me; could you please explain what you mean by ":-/" and/or
where you should have added it?
More information about the Tutor
mailing list