文、意如
小到大排序
print(sorted(a))
範例:
mylist=[28, 16, 39, 56, 78, 88]
print("mylist排序前",mylist)#mylist排序前 [28, 16, 39, 56, 78, 88]
print("mylist排序後",sorted(mylist))#mylist排序後 [16, 28, 39, 56, 78, 88]
mytuple=(39, 56, 78, 88,9, 0, -1, 3, 8, 28, 16)
print("mytuple排序前",mytuple)#mytuple排序前 (39, 56, 78, 88, 9, 0, -1, 3, 8, 28, 16)
print("mytuple排序後",sorted(mytuple)) #tuple->list #mytuple排序後 [-1, 0, 3, 8, 9, 16, 28, 39, 56, 78, 88]
大到小排序
print(sorted(a,reverse=True))
Yiru@Studio - 關於我 - 意如