From 637a5098ef7453717dec7a0bfb8be9201827d152 Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 21 Nov 2026 18:58:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=88=97=E8=A1=A8=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=9A=84=E5=8F=82=E6=95=B0=E5=92=8C=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E4=B8=8B=E6=A0=87=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Article/PythonBasis/python3/List.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Article/PythonBasis/python3/List.md b/Article/PythonBasis/python3/List.md index 8c6f92c7..edabb878 100644 --- a/Article/PythonBasis/python3/List.md +++ b/Article/PythonBasis/python3/List.md @@ -232,11 +232,11 @@ print(name) |list.count(obj)|统计某个元素在列表中出现的次数| |list.extend(seq)|在列表末尾一次性追加另一个序列中的多个值(用新列表扩展原来的列表)| |list.index(obj)|从列表中找出某个值第一个匹配项的索引位置| -|list.insert(index, obj)|将对象插入列表| -|list.pop(obj=list[-1])|移除列表中的一个元素(默认最后一个元素),并且返回该元素的值| -|list.remove(obj)|移除列表中的一个元素(参数是列表中元素),并且不返回任何值| +|list.insert(index, obj)|在指定下标处插入元素,原位置及其后面的元素向后移动| +|list.pop([index])|删除并返回指定下标的元素,省略下标时删除并返回最后一个元素| +|list.remove(obj)|删除第一个等于 obj 的元素,找不到时抛出 ValueError| |list.reverse()|反向列表中元素| -|list.sort([func])|对原列表进行排序| +|list.sort(*, key=None, reverse=False)|对原列表进行排序。用 key 指定排序依据,用 reverse=True 指定降序| ## 8、实例 ## @@ -270,7 +270,7 @@ print('\n4.在末尾添加新用户') print(user) # 5.又新增了一个用户,可是这个用户是 VIP 级别的学生,需要放在第一位,可以通过 insert 方法插入到指定的位置 -# 注意:插入数据的时候注意是否越界,索引不能超过 len(user)-1 +# 下标 0 表示插在最前面,下标等于或大于 len(user) 时插在末尾 user.insert(0,'VIP用户') print('\n5.指定位置添加用户') print(user)