Python列表详解(二)
来源:互联网 发布:python list函数 编辑:程序博客网 时间:2024/05/15 11:19
交互解释器
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.
关于列表的操作
定义列表
>>> world = ['a','b','c',['qwer','asdf'],1,2,3,'ChangerLee']
下标正取值
>>> world[1]'b'>>> world[3]['qwer', 'asdf']
下标反取值
>>> world[-2]3
元素全选操作符
>>> world[:]['a', 'b', 'c', ['qwer', 'asdf'], 1, 2, 3, 'ChangerLee']
元素片段操作
>>> world[2:]['c', ['qwer', 'asdf'], 1, 2, 3, 'ChangerLee']>>> world[:3]['a', 'b', 'c']>>> world[1:3]['b', 'c']>>>
列表的长度
>>> world['a', 'b', 'c', ['qwer', 'asdf'], 1, 2, 3, 'ChangerLee']>>> len(world)8
id方法:查看python中对象内存序列的内建方法
>>> help(id)Help on built-in function id in module __builtin__:id(...) id(object) -> integer Return the identity of an object. This is guaranteed to be unique among simultaneously existing objects. (Hint: it's the object's memory address.)
列表的复制
>>> world['a', 'b', 'c', ['qwer', 'asdf'], 1, 2, 3, 'ChangerLee']>>> anotherworld=world[:]>>> id(world)50136648L>>> id(anotherworld)50137992L
列表取别名
>>> world['a', 'b', 'c', ['qwer', 'asdf'], 1, 2, 3, 'ChangerLee']>>> sameworld=world>>> id(world)50136648L>>> id(sameworld)50136648L>>>
列表的连接
>>> world['a', 'b', 'c', ['qwer', 'asdf'], 1, 2, 3, 'ChangerLee']>>> anotherworld+world['a', 'b', 'c', ['qwer', 'asdf'], 1, 2, 3, 'ChangerLee', 'a', 'b', 'c', ['qwer', 'asdf'], 1, 2, 3, 'ChangerLee']>>> [1,2,3]+[4,5,6][1, 2, 3, 4, 5, 6]>>> list1[5, 2, 3]>>> list1*3[5, 2, 3, 5, 2, 3, 5, 2, 3]>>> list1[5, 2, 3]
列表的逻辑操作
注意:列表的逻辑比较是列表的第一个元素的比较
>>> list1 = [1,2,3]>>> list2 = [4,5,6]>>> list1 < list2True>>> list1[0]=5>>> list1[5, 2, 3]>>> list1 < list2False
列表存在性判断not in 和in
>>> list2[4, 5, 6]>>> 5 in list2True>>> 3 not in list2True
列表中的列表元素存在性判断
>>> list1 = [1,2,3,['a','b','c']]>>> list1[3]['a', 'b', 'c']>>> 'a' in list1False>>> 'a' in list1[3]True>>> list1[3][2]'c'>>>
0 0
- Python列表详解(二)
- python学习笔记(二)列表(List)操作方法详解
- Python列表详解(一)
- 序列之二 列表(Python)
- Python笔记(二) 列表、字典
- Python列表操作自定义函数(二)
- python学习系列(二)--- 列表操作
- python(二)列表,元组,循环
- Python (二)列表、元组
- 学习python总结(二)。。。列表
- Python--序列学习(二)--列表
- python基础数据类型(二):列表
- python(二) 字符串 列表
- Python列表切片详解([][:][::])
- python列表详解
- Python列表切片详解([][:][::])
- Python 列表list详解
- Python yield 详解(二)
- Linux (centos7) 安装Git搭建服务器以及客户端安装
- 注解该如何使用
- TJU 1038 素数表
- VLFeat在matlab中的使用
- 内部类
- Python列表详解(二)
- 数据库
- PE 211
- hibernate入门
- 什么是SDK
- AlertDialog 加载自定义布局点击按钮消失的方法
- 大数据处理需要用到的编程语言开发语言
- Unity5.X批清理AssetBundle的名称
- iOS 如何对音频、视频合成,配音、卡拉OK技术