>>>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 >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 | 統(tǒng)計某個元素在列表中出現(xiàn)的次數(shù) |
| extend | 可以在列表尾一次性追加另一個序列的多個值 |
| index | 從列表中找出某一個值第一匹配項的索引位置 |
| insert | 用于將對象插入到列表中 |
| pop | 移除列表中的一個元素(默認為最后一個)并返回該元素的值:它是唯一一個既能修改列表又返回元素值(其它的都是None)的列表方法 |
| remove | 移除列表中某個值的第一個匹配項 |
| reverse | 把列表中的元素反向存放 |
| sort | 排序,可以自定義排序函數(shù) |
>>> 1,2,3(1, 2, 3)>>> (1,)(1,)>>> (1)1
>>> tuple([1,2,3])(1, 2, 3)整理過程中感覺到一股強烈的高級語言對Erlang的壓制性力量,怎么辦。。。。。。

新聞熱點
疑難解答