list slice is copy
x = [1, 1, 2, 3, 5, 8, 13, 21, 34]
y = x[2:5]
print(y) # [2, 3, 5]
x[2] = 20
print(x) # [1, 1, 20, 3, 5, 8, 13, 21, 34]
print(y) # [2, 3, 5]
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
x = [1, 1, 2, 3, 5, 8, 13, 21, 34]
y = x[2:5]
print(y) # [2, 3, 5]
x[2] = 20
print(x) # [1, 1, 20, 3, 5, 8, 13, 21, 34]
print(y) # [2, 3, 5]