官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 浦城县| 谷城县| 枣阳市| 普兰县| 德令哈市| 贵定县| 万年县| 布尔津县| 湟源县| 治县。| 弋阳县| 凤山市| 渭源县| 资中县| 玉环县| 哈巴河县| 彭阳县| 灵璧县| 盐边县| 诏安县| 金川县| 大同市| 云阳县| 新竹市| 普洱| 泌阳县| 荔波县| 炉霍县| 揭阳市| 拉萨市| 永宁县| 贵溪市| 邛崃市| 鄢陵县| 太谷县| 石狮市| 启东市| 黎川县| 霍邱县| 顺平县| 吉木乃县|