A collection of examples for when you're confused by Python's slice notation

First definition

x=[1,2,3,4,5,6]

General

From before

x[1:]
#[2,3,4,5,6]

From the back

x[:1]
#[1]

minus

From before

x[-1:]
#[6]

From the back

x[:-1]
#[1,2,3,4,5]

zero

From before

x[0:]
#[1,2,3,4,5,6]

From the back

x[:0]
#[]

over-

From before

x[9:]
#[]

From the back

x[:9]
#[1,2,3,4,5,6]

Recommended Posts

A collection of examples for when you're confused by Python's slice notation
[Django] A collection of scripts that are convenient for development
A collection of methods used when aggregating data with pandas
Gold needle for when it becomes a stone by looking at the formula of image processing