19 lines
374 B
Python
19 lines
374 B
Python
# 1、统计某元素在列表中的数量
|
|
# list.count(元素)
|
|
list=[1,2,3,34,5,6,7,888,99,1,1,1,1,4,5,7]
|
|
print(list.count(1))
|
|
|
|
# 2、和列表相关的函数
|
|
# len() 统计长度
|
|
list=['a','b','c','d']
|
|
print(len(list))
|
|
|
|
# sorted 是sort()函数的扩展 可以对列表的元素排序 同时不会修改原列表
|
|
list=[12,2,3,4,46,78,7,8,9,20,35]
|
|
print(sorted(list))
|
|
|
|
|
|
|
|
|
|
|