码迷,mamicode.com
首页 > 编程语言 > 详细

python 数据类型 序列——列表

时间:2015-08-18 22:51:29      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:python

python 数据类型 序列——列表

**列表**
list是处理一组有序项目的数据结构,即你可以在一个列表中存储一个序列的项目。
列表是可变类型的数据。
用[]表示列表,包含了多个以逗号分割开的数字或者字符串。


>>> list1 = [‘1‘,‘chen‘,‘陈‘]
>>> list2 = [1,2,3,4]
>>> list3 = ["str1","str1","22"]
>>> list4 = []
>>> list5 = [‘chen‘,18,"male"]
>>> list5[1] = 19
>>> list5
[‘chen‘, 19, ‘male‘]
>>> id(list5)
4429403272
>>> list5[1] = 21
>>> id(list5)
4429403272
>>> list5 = [‘ch‘,1,‘female‘]
>>> id(list5)
4429403416
>>> list5[3] = ‘1234‘
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list assignment index out of range
>>> list5.append(‘1234‘)
>>> list5
[‘ch‘, 1, ‘female‘, ‘1234‘]
>>> list5.append(‘ll‘)
>>> list5.append(‘1234‘)
>>> list5
[‘ch‘, 1, ‘female‘, ‘1234‘, ‘ll‘, ‘1234‘]
>>> list5.remove(‘1234‘)
>>> list5
[‘ch‘, 1, ‘female‘, ‘ll‘, ‘1234‘]
>>> list5.remove(‘1234‘)
>>> list5
[‘ch‘, 1, ‘female‘, ‘ll‘]
>>> list5.remove(list5[3])
>>> list5
[‘ch‘, 1, ‘female‘]
>>> help(list.append)

>>> help(list)

>>> list5
[‘ch‘, 1, ‘female‘]
>>> del(list5[1])
>>> list5
[‘ch‘, ‘female‘]

版权声明:本文为博主原创文章,未经博主允许不得转载。

python 数据类型 序列——列表

标签:python

原文地址:http://blog.csdn.net/chenguibao/article/details/47760199

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!