Python list sorted reverse, sort, sorted Operation

1.reverse reverse the sort list

x = [1,5,2,3,4]

x.reverse()

Output: [4, 3, 2, 5, 1]

 

2.sort list is sorted, no return value

Positive sequence:

a = [5,7,6,3,4,1,2]

a.sort()

Output: [1, 2, 3, 4, 5, 6, 7]

Reverse:

a.sort(reverse=False)

Output: [7,6,5,4,3,2,1]

 

3.sorted sort the list, there is a return value

a = [5,7,6,3,4,1,2]

b = sorted(a)

Output:

a----[5, 7, 6, 3, 4, 1, 2]

b----[1, 2, 3, 4, 5, 6, 7]

Guess you like

Origin www.cnblogs.com/bubutianshu/p/11265686.html