python 数据类型 序列——列表
浏览次数:
发布时间:2015-08-21 11:38
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 , line 1, in
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']
相关报道:
介绍Android为了达到节约电源的目的,在屏幕没有操作时便会自动息屏,那么比如我们在播放视频时,尽管对屏幕没有操作,但是我们此时是不希望它息屏的,如果视频 更多
这里需要特别注意一下, Python 是解释类型的语言. 会允许在定义A函数之前没有定义B函数的情况下,函数A调用函数B. def func1():print "Hello fun1"fun2()def func2():print "Hello func2"fun1() 这样做是可以的.但是试想一下, 如果函数2也调用函数1呢 更多