Lists: Constructing Lists
Slicing
Syntax: list[i:j]
E.g.
>>> l = [1, ["2", 4], 3.0]
>>> l[1:2]
[['2', 4]]
>>> l[0:-2]
[1]
>>> l[1:-2]
[]
>>> l[1:-3]
[]
>>> l[1:3] = [2, 3]
>>> l
[1, 2, 3]
Previous slide
Next slide
Back to first slide
View graphic version