Search
ctrl/
Ask AI
Light
Dark
System

Operators

Subtopics

The same 3 types that share the indexing operator (str, bytes, and arrays) also share the ability to cut out a slice of values between two given indexes. The operator returns all the elements starting with the first index value given and up to, but not including the second index value:

Input
Run
Output Objects
Press the 'Run' button to evaluate the input
Input
Run
Output Objects
Press the 'Run' button to evaluate the input
Input
Run
Output Objects
Press the 'Run' button to evaluate the input

A negative index value is interpreted as a position relative to the end of the string or array. In other words, it begins indexing from the right instead of the left.

Input
Run
Output Objects
Press the 'Run' button to evaluate the input

You can even use a negative value for both indexes in your slice. So a slice from the 9th element from the right to the 5th element from the right would look like this:

Input
Run
Output Objects
Press the 'Run' button to evaluate the input