Lists are mutable
The syntax for accessing the elements of a list is the same as for accessing the characters of a string – the bracket operator ([ ]). The expression inside the brackets specifies the index. Unlike strings, lists are mutable. When the bracket operator appears on the left side of an assignment, it identifies the element of the list that will be assigned. You can think of a list as a relationship between indices and elements. This relationship is called a mapping; each index ‘maps to’ one of the elements.
Lists are represented by boxes with the word ‘list’ outside and the elements of the list inside. test refers to a list with three elements indexed 0, 1 and 2.
The bracket operator can appear anywhere in an expression. When it appears on the left side of an assignment, it changes one of the elements in the list.
List indices work the same way as string indices:
- Any integer expression can be used as an index
- If you try to read or write an element that does not exist, you get an IndexError
- If an index has a negative value, it counts backward from the end of the list
The in operator also works in lists.

from Thinking in Python
Lists are mutable的更多相关文章
- Think Python - Chapter 10 - Lists
10.1 A list is a sequenceLike a string, a list is a sequence of values. In a string, the values are ...
- Python学习笔记(迭代、模块扩展、GUI 、编码处理等)
PythonIDLE中的编码处理 http://www.tuicool.com/articles/NbyEBr 原文标题:Python中实际上已经得到了正确的Unicode或某种编码的字符,但是看起来 ...
- 关于Python中数据对象的可变性
先贴上Python官网中对数据模型描述的几段话.(在python官网的 语言参考>>数据模型 那部分) Every object has an identity, a type and a ...
- Python Tutorial 学习(五)--Data Structures
5. Data Structures 这一章来说说Python的数据结构 5.1. More on Lists 之前的文字里面简单的介绍了一些基本的东西,其中就涉及到了list的一点点的使用.当然,它 ...
- (python数据分析)第03章 Python的数据结构、函数和文件
本章讨论Python的内置功能,这些功能本书会用到很多.虽然扩展库,比如pandas和Numpy,使处理大数据集很方便,但它们是和Python的内置数据处理工具一同使用的. 我们会从Python最基础 ...
- Python - 2. Built-in Collection Data Types
From: http://interactivepython.org/courselib/static/pythonds/Introduction/GettingStartedwithData.htm ...
- A Complete Tutorial to Learn Data Science with Python from Scratch
A Complete Tutorial to Learn Data Science with Python from Scratch Introduction It happened few year ...
- objects & values & types
[objects & values & types] 1.Every object has an identity, a type and a value. An object’s i ...
- [python数据结构] hashable, list, tuple, set, frozenset
学习 cs212 unit4 时遇到了 tuple, list, set 同时使用的问题,并且进行了拼接.合并操作.于是我就被弄混了.所以在这里进行一下总结. hashable and unhasha ...
随机推荐
- video_capture模块分析
1. 对外接口 VideoCaptureModule 控制接口 VideoCaptureDataCallback Vie中的ViECapturer继承,用于响应抓包数据 2 ...
- [博弈] hdu 3683 Gomoku
题意: 两个人下五子棋.给你现有棋盘,推断在三步之内的胜负情况. 输出分为几种. 1.棋盘不合法 2.黑或白在第一步赢下在(x,y)点,多个输出x最小的.y最小的. 3.输在第二步 4.黑或白在第三步 ...
- _00017 Kafka的体系结构介绍以及Kafka入门案例(0基础案例+Java API的使用)
博文作者:妳那伊抹微笑 itdog8 地址链接 : http://www.itdog8.com(个人链接) 博客地址:http://blog.csdn.net/u012185296 博文标题:_000 ...
- Pocket英语语法---五、形式主语是怎么回事
Pocket英语语法---五.形式主语是怎么回事 一.总结 一句话总结:1.to不定式或动名词可以在主语的位置上,但一般用it代替它做形式主语.这种情况it叫形式主语. It's a great ho ...
- .net core 实现npoi导出
Nuget 安装 NPOI 2.4.1 工作时间写着测试玩玩 public void ExportDataToExcel() { var workbook = new HSSFWorkbook(); ...
- 基于Zepto移动端下拉加载(刷新),上拉加载插件开发
写在前面:本人水平有限,有什么分析不到位的还请各路大神指出,谢谢. 这次要写的东西是类似于<今日头条>的效果,下拉加载上啦加载,这次做的效果是简单的模拟,没有多少内容,下面是今日头条的移动 ...
- 计算sigma
1.计算平均值Avg Avg = (a0 + a1 + ......+ an-1) / n 2.计算sigma sigma = sqrt( ( (a0-avg) ^2 + (a1-avg) ^2 ...
- MySQL日期数据类型和时间类型使用总结
转自: http://blog.chinaunix.net/space.php?uid=11327712&do=blog&id=32416 MySQL 日期类型:日期格式.所占存储空间 ...
- js函数 DOM操作
回学校了两天请了两天假,数组和方法的内容周末一定补上! 今天介绍一下JavaScript函数 Function 一.基础内容 1.定义 函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块. f ...
- 【原创】Apache和基于虚拟主机的Tomcat集群方案
最近建设了北京某政府机构的网站,网站前段使用Apache做负载均衡,后端使用Tomcat做的集群,基于虚拟主机的方式访问,并且实现了静态资源和动态资源的分离. 开始的建设方案有两种,一种是使用apac ...