Introduction To Computation and Programming Using Python, Revised - Guttag, John v..75
Introduction To Computation and Programming Using Python, Revised - Guttag, John v..75
5.2
Occasionally, the fact that square brackets are used for literals of type list,
indexing into lists, and slicing lists can lead to some visual confusion. For
example, the expression [1,2,3,4][1:3][1], which evaluates to 3, uses the
square brackets in three different ways. This is rarely a problem in practice,
because most of the time lists are built incrementally rather than written as
literals.
Lists differ from tuples in one hugely important way: lists are mutable. In
contrast, tuples and strings are immutable. There are many operators that can
be used to create objects of these immutable types, and variables can be bound
to objects of these types. But objects of immutable types cannot be modified.
On the other hand, objects of type list can be modified after they are created.
The distinction between mutating an object and assigning an object to a variable
may, at first, appear subtle. However, if you keep repeating the mantra, In