Files
2025PY/day14/03-列表方法的总结.py
2025-05-22 16:50:44 +08:00

34 lines
1016 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 总结列表的常用方法:
# 1.list.index(元素) : 找对应元素的索引,如果没有找到就报错
# 2.list.append(元素或者列表) : 将对应的元素或者列表放到列表的后面
# 3.list.extend(元素或者列表) : 功能和上面的append一样
# 4.list.pop(索引) : 删除索引位置的元素,如果没有设置索引,默认删除最后一个元素
# 5.list.remove(元素) : 删除列表中第一个和括号里面值相同的元素
# 6.list.clear() : 删除列表中的所有元素
# 7.list.insert(索引,插入的元素或列表) : 在对应的索引位置插入元素或者列表
# 8.list.reverse() : 反转列表里面的所有元素
# 9.list.sort(reverse=True) : 排序,默认是升序无需参数如果是降序就要设置参数reverse=True
# 10.list.count(元素) : 统计列表中某个元素出现的次数
# 函数
# len(列表) : 统计列表中元素的个数
# sorted(列表) : 排序列表和list.sort类型但是sorted不改变原列表