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

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.

主站蜘蛛池模板: 防城港市| 乌拉特中旗| 左贡县| 吉林市| 正阳县| 克拉玛依市| 隆子县| 石景山区| 桐城市| 婺源县| 冕宁县| 彰化市| 榆树市| 正镶白旗| 长泰县| 昆明市| 贡嘎县| 遂溪县| 水富县| 托克托县| 高碑店市| 蒙城县| 玉龙| 石楼县| 志丹县| 石泉县| 三台县| 咸丰县| 平阴县| 射阳县| 集安市| 南华县| 凤阳县| 永德县| 黑水县| 洞头县| 得荣县| 开原市| 罗平县| 浪卡子县| 沙河市|