Python列表的方法
本节内容如下:
- append
- extend
- insert
- remove
- pop
- clear
- count
- sort
- reverse
append
list.append(x) 将项目添加到列表的末尾,例如:
l1
=
[
1
,
2
,
3
]
l1.append(
100
)
(l1)
# [1, 2, 3, 100]
extend
list.extend(L) 通过添加另外一个列表来扩展列表,例如:
l1
=
[
1
,
2
,
3
]
l2
=
[
4
,
5
,
6
]
l1.extend(l2)
(l1)
# [1, 2, 3, 100, 4, 5, 6]
insert
list.insert(i, x) 在给定位置插入项目。i参数的前面,例如:
l1
=
[