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.

全部评论

相关推荐

昨天 20:46
武汉大学 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务