on slices, negative indices, which are the equivalent procedures?

Jack Brandom jbrandom at example.com
Thu Aug 5 13:35:08 EDT 2021


The FAQ at 

  https://docs.python.org/3/faq/programming.html#what-s-a-negative-index

makes me think that I can always replace negative indices with positive
ones --- even in slices, although the FAQ seems not to say anything
about slices.  

With slices, it doesn't seem to always work.  For instance, I can
reverse a "Jack" this way:

>>> s = "Jack Brandom"
>>> s[3 : -13 : -1]
'kcaJ'

I have no idea how to replace that -13 with a positive index.  Is it
possible at all?  

But this example gives me the idea that perhaps each slice is equivalent
to a certain loop (which I could write in a procedure).  So I'm looking
for these procedures.  If I can have the procedures in mind, I think I
will be able to undersand slices without getting surprised.

Do you have these procedures from the top of your mind?  While I haven't
given up yet, I am not getting too close.  Thank you!


More information about the Python-list mailing list