- 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.
推薦閱讀
- Web前端開(kāi)發(fā)技術(shù):HTML、CSS、JavaScript(第3版)
- Vue.js設(shè)計(jì)與實(shí)現(xiàn)
- Dynamics 365 Application Development
- Visual Basic程序設(shè)計(jì)教程
- Programming ArcGIS 10.1 with Python Cookbook
- Python機(jī)器學(xué)習(xí)編程與實(shí)戰(zhàn)
- Learning Apache Mahout Classification
- Expert Data Visualization
- The Complete Coding Interview Guide in Java
- MySQL從入門(mén)到精通(軟件開(kāi)發(fā)視頻大講堂)
- Mastering Web Application Development with AngularJS
- Cocos2d-x Game Development Blueprints
- JavaScript動(dòng)態(tài)網(wǎng)頁(yè)編程
- Julia數(shù)據(jù)科學(xué)應(yīng)用
- Java高并發(fā)編程詳解:深入理解并發(fā)核心庫(kù)