>>>num=[0,1,2,3,4]>>>num[1]1>>>num[-1]4
>Num=[0,1,2,3,4].>lists:nth(Num,2).
1.2 python可以分片:使用索引可以访问单个元素,使用分片可以访问一定范围内的元素:
>>>tag='<a href="http://www.google.com">google web site</a>'>>> tag[9:30] 'http://www.google.com'>>> tag[32:-4]'google web site'
>>> tag[-20:-4]'>google web site'
>>> num[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]>>> num[0:11:2][0, 2, 4, 6, 8, 10]
>>> num[:][0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> num+[1,2,3][0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3]
>>> num.extend([1,2,3])>>> num[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3]
> [1,2,3]++[4,5,6].[1,2,3,4,5,6]> lists:append([1,2,3],[4,5,6]).[1,2,3,4,5,6]
>>> [1]*4[1, 1, 1, 1]
空列表可以使用[]来表示,
>>> [None]*10[None, None, None, None, None, None, None, None, None, None]
> lists:duplicate(4,1). [1,1,1,1]
>>> num[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3]>>> 1 in numTrue>>> 100 in numFalse>>> [1,2] in num False>>> "aaa" in "aaatest"True
>>> list("test")['t', 'e', 's', 't']>>> list("test")=="test"False
> lists:member(21,[21,2,3,41,1]).true> lists:member(22,[21,2,3,41,1]).false
>>> num[1, 2, 3]>>> num[2]=100>>> num[1, 2, 100]
>>> num[100]Traceback (most recent call last): File "<stdin>", line 1, in <module>IndexError: list index out of range
>>> num[1, 2, 100]>>> del num[2]>>> num[1, 2]>>> del num[10]Traceback (most recent call last): File "<stdin>", line 1, in <module>IndexError: list assignment index out of range
>>> name=list("test")>>> name['t', 'e', 's', 't']>>> name[2:]=['c','h']>>> name['t', 'e', 'c', 'h']>>> name[2:]=['c','h','e','r']>>> name['t', 'e', 'c', 'h', 'e', 'r']
>>> name[1:1]=['t','e','s','t']>>> name['t', 't', 'e', 's', 't', 'e', 'c', 'h', 'e', 'r']
>>> name[1:4]=[]>>> name['t', 't', 'e', 'c', 'h', 'e', 'r']>>> name[1:4]=[]>>> name['t', 'h', 'e', 'r']
append | 在列表尾追加新的对象 |
count | 统计某个元素在列表中出现的次数 |
extend | 可以在列表尾一次性追加另一个序列的多个值 |
index | 从列表中找出某一个值第一匹配项的索引位置 |
insert | 用于将对象插入到列表中 |
pop | 移除列表中的一个元素(默认为最后一个)并返回该元素的值:它是唯一一个既能修改列表又返回元素值(其它的都是None)的列表方法 |
remove | 移除列表中某个值的第一个匹配项 |
reverse | 把列表中的元素反向存放 |
sort | 排序,可以自定义排序函数 |
>>> 1,2,3(1, 2, 3)
>>> (1,)(1,)>>> (1)1
>>> tuple([1,2,3])(1, 2, 3)
整理过程中感觉到一股强烈的高级语言对Erlang的压制性力量,怎么办。。。。。。
新闻热点
疑难解答