Mutability

As mentioned several times, one of the special things about lists is that they are mutable; that is, they can be modified in place without creating a new object. The big concern with this is remembering that, if you do this, it can affect other references to it. However, this isn't usually a large problem; it's more of something to keep in mind if you get program errors.

The following screenshot is an example of changing a list using index offset, slicing, and deleting elements:

Changing a list

Line 12 changes the value for the element at index 1 (second position in the list). Line 14 swaps out the first two elements for new values. Line 16 deletes the first element; removing multiple elements through slicing is also allowed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.239.41