通过指定关键字参数,对列表中的元素进行降序排序
lst.sort(reverse=True) # reverse=True表示降序排序,reverse=False 表示升序排序
print(‘降序排序后的列表:’,lst)
升序排序
lst.sort(reverse=False)
print(‘升序排序后的列表:’,lst)
print(‘-----------------使用内置函数sorted()进行排序,将产生一个新的列表对象------------------------------------’)
lst = [8, 6, 23, 12, 17, 15, 35, 24]
new_lst = sorted(lst)
print(‘原列表:’, lst, id(lst))
print(‘排序后列表:’, new_lst, id(new_lst))
print(‘------------------指定关键字参数,降序排序------------------