sorted and sort()
有序的列表
https://www.nowcoder.com/practice/855d960ba868480ba6e626914018ded4
str1 = "Python" my_list = list(str1) print(sorted(my_list)) print(my_list) my_list.sort(reverse=True) print(my_list)
So pay attention to the function sorted :https://www.runoob.com/python/python-func-sorted.html and the Python List sort() :https://www.runoob.com/python/att-list-sort.html
Sort and sorted differences:
Sort is a method applied to List, and Sorted can sort all the iterative objects.
The Sort method of the list returns to operate the existence list without returning values, and the built -in function Sorted method returns a new list, not the operation on the original basis.
查看1道真题和解析