@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 969 / 12833)
Slices are more forgiving of bad offsets than are single-index lookups. A slice offset earlier than the beginning of a string is treated as 0, and one after the end is treated as -1, as is demonstrated in this next series of examples.
>>> letters[-50:]
'abcdefghijklmnopqrstuvwxyz'
>>> letters[-51:-50]
''
>>> letters[:70]
'abcdefghijklmnopqrstuvwxyz'
>>> letters[70:71]
''
I understand the above.
one after the end is treated as -1
I don't think I can find an example of.
Does it mean one after the end is treated by reducing by 1 (indexes that exceed the end are treated as 1 minus)?
Recommended Posts