Skip to content

Latest commit

 

History

History
25 lines (18 loc) · 390 Bytes

4.1.4 列表的排序.md

File metadata and controls

25 lines (18 loc) · 390 Bytes

4.1.4 列表的排序

num_list = [6, 8, 4, 1, 10]

print(num_list)

# 升序(reverse=False ,默认升序)
num_list.sort()
# [1, 4, 6, 8, 10]
print(num_list)

# 降序
num_list.sort(reverse=True)
# [10, 8, 6, 4, 1]
print(num_list)

# 逆序(反转)
name_list = ["张三", "李四", "王五"]
name_list.reverse()
# ['王五', '李四', '张三']
print(name_list)