- Learn Programming in Python with Cody Jackson
- Cody Jackson
- 131字
- 2021-06-10 19:06:10
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.
推薦閱讀
- iOS Game Programming Cookbook
- 玩轉Scratch少兒趣味編程
- Apache ZooKeeper Essentials
- Cocos2d-x學習筆記:完全掌握Lua API與游戲項目開發 (未來書庫)
- Python從入門到精通
- Clean Code in C#
- Python:Deeper Insights into Machine Learning
- SQL Server 2016 從入門到實戰(視頻教學版)
- Xamarin Blueprints
- ABAQUS6.14中文版有限元分析與實例詳解
- Learning Concurrency in Python
- LabVIEW數據采集(第2版)
- C++從零開始學(視頻教學版)(第2版)
- 亮劍C#項目開發案例導航
- Game Development with SlimDX