Python> Slice> A slice offset earlier than the beginning of a string is treated as 0, and one after the end is treated as -1

@ 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

Python> Slice> A slice offset earlier than the beginning of a string is treated as 0, and one after the end is treated as -1
Cut a part of the string using a Python slice
[python] [meta] Is the type of python a type?
How to input a character string in Python and output it as it is or in the opposite direction.
The answer of "1/2" is different between python2 and 3
A discussion of the strengths and weaknesses of Python
Python tricks: a combination of enumerate () and zip (), checking if a string can be converted to a number, sorting the string as a number
Acquire the data of Mitsubishi UFJ International Investment Trust eMAXIS with Python and make a graph with the beginning of the term as 100
How to check in Python if one of the elements of a list is in another list
Check if the string is a number in python
Basics of Python learning ~ What is a string literal? ~
Find out the apparent width of a string in python
Remove double-byte spaces before and after the character string (python)
[python] plot the values ​​before and after the conversion of yeojohnson conversion
Extract the value of dict or list as a string
Python will fail if there is a space after the backslash
Save the result of the life game as a gif with python
Format when passing a long string as an argument of python
Get the formula in an excel file as a string in Python
The story of Python and the story of NaN
First Python 3 ~ The beginning of repetition ~
What is the XX file at the root of a popular Python project?
Calculate the shortest route of a graph with Dijkstra's algorithm and Python
If you want a singleton in python, think of the module as a singleton
[Introduction to Python] What is the difference between a list and a tuple?
Migration from Python2 to Python3 (Python2 is rebuilt as a virtual environment and coexists)
<Python> A quiz to batch convert file names separated by a specific character string as part of the file name
Try to find the probability that it is a multiple of 3 and not a multiple of 5 when one is removed from a card with natural numbers 1 to 100 using Ruby and Python.