列表list[]:
1:ls=['jk','jk','kjh']
ls
['jk', 'jk', 'kjh']:
2、输出索引:ls.index('jk')
0
3、元素追加: ls.append('hk')
ls
['jk', 'jk', 'kjh', 'hk']
4、元素扩展:ls.extend('hjgskjdf')
ls
['jk', 'jk', 'kjh', 'hk', 'h', 'j', 'g', 's', 'k', 'j', 'd', 'f']
5、元素排序:ls.sort()
ls
['d', 'f', 'g', 'h', 'hk', 'j', 'j', 'jk', 'jk', 'k', 'kjh', 's']
6、元素删除:
ls.pop()
's'
7、元素遍历:
for i in ls:
print(i)
d
f
g
h
hk
j
j
jk
jk
k
kjh
ls[1]
'f'
>>> ls[-1]
'kjh'
>>> ls
['d', 'f', 'g', 'h', 'hk', 'j', 'j', 'jk', 'jk', 'k', 'kjh']
>>> ls[0:4]
['d', 'f', 'g', 'h']
>>> ls[2]='yaoayao'
>>> ls
['d', 'f', 'yaoayao', 'h', 'hk', 'j', 'j', 'jk', 'jk', 'k', 'kjh']
>>> len(ls)
11
>>> max(ls)
'yaoayao'
>>> min(ls)
'd'