004: 基本数据类型-List
2015-12-30 16:35
323 查看
List 也就是数组,但是这个数组是动态的,用中括号与逗号创建。
Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type.
1) Like strings (and all other built-in sequence type), lists can be indexed and sliced.
2) All slice operations return a new list containing the requested elements.
3) Lists also support operations like concatenation.用 + 进行连接
4) Unlike strings, which are immutable, lists are a mutable type.
5) You can also add new items at the end of the list, by using the
6) Assignment to slices is also possible, and this can even change the size of the list or clear it entirely.
7) The built-in function
8) It is possible to nest lists (create lists containing other lists).
9) There is a way to remove an item from a list given its index instead of its value: the
以下是今天做的一些小练习
关于list的slice:
1,一共可以接受三个参数,start, stop, step. 其中start与stop是必选参数, step是可选参数, 默认为1。
start可以接受负数,如果为负数,则意思为从倒数第几个开始。
stop也可以接受负数,如果为负数,则意思为倒数几个结束。
如果step为正数,需要 stop>start 才有意义, 如果step为负数, 需要stop<start才有意义。
Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type.
1) Like strings (and all other built-in sequence type), lists can be indexed and sliced.
2) All slice operations return a new list containing the requested elements.
3) Lists also support operations like concatenation.用 + 进行连接
4) Unlike strings, which are immutable, lists are a mutable type.
5) You can also add new items at the end of the list, by using the
append()method.
6) Assignment to slices is also possible, and this can even change the size of the list or clear it entirely.
7) The built-in function
len()also applies to lists.
8) It is possible to nest lists (create lists containing other lists).
9) There is a way to remove an item from a list given its index instead of its value: the
delstatement.
del list_example[index] del list_example[start:stop]
以下是今天做的一些小练习
关于list的slice:
1,一共可以接受三个参数,start, stop, step. 其中start与stop是必选参数, step是可选参数, 默认为1。
start可以接受负数,如果为负数,则意思为从倒数第几个开始。
stop也可以接受负数,如果为负数,则意思为倒数几个结束。
如果step为正数,需要 stop>start 才有意义, 如果step为负数, 需要stop<start才有意义。
a = [1,2,3,4,5] a[:] # [1, 2, 3, 4, 5] a[0:3] # [1, 2, 3] a[2:5] # [3, 4, 5] a[-3:-1] # [3, 4] a[::-1] # [5, 4, 3, 2, 1] a[-1:-5:-1] # [5, 4, 3, 2]
相关文章推荐
- 递归下降分析法
- 利用jQuery中的serialize方法大量获取页面中表单的数据,发送的服务器
- mysql 查看binlog 操作日志及恢复数据
- 062 - Unique Paths
- 备忘录实现过程
- hdu1087
- 数据结构 JAVA描述(六) 图的创建 (邻接矩阵+邻接表)
- WEB程序员需要掌握的十大MySQL优化技巧
- 递归下降语法分析程序设计
- 061 - Rotate List
- Style Scope Agile Edition―免费版商业智能产品
- postgresql学习line
- 解决android sdk无法访问Google的问题
- eclipse重新设置workspace路径
- JavaScriptCore在实际项目中的使用的坑
- AOP(2)
- iOS9 搜索API
- how to write one native program based on android source build system
- KVC设置unfinderKey和与系统关键字相同key的解决
- Linux下安装Tomcat7