»Language: Slices

Slices are an efficient way to create a substring or sublist from an existing string or list, respectively.

The syntax for creating a slice is:

a[low : high]

low is the lowest index to slice from. The resulting slice includes the value at low. high is the index to slice to. The resulting slice will not include the value at high. The length of the resulting list or string is always high - low.

a = [1, 2, 3, 4, 5]
b = a[1:4] // [2, 3, 4]

a = "hello"
b = a[1:4] // "ell"