The sort() method sorts the elements of a given list.
The sort() method sorts the elements of a given list in a specific order - Ascending or Descending.
The syntax of sort() method is:
list.sort(key=..., reverse=...)
sorted(list, key=..., reverse=...)
sort() Parameters
reverse - If true, the sorted list is reversed (or sorted in Descending order)
key - function that serves as a key for the sort comparison
Example:-
vowels = ['e', 'a', 'u', 'o', 'i']
vowels.sort()
print('Sorted list:', vowels)
vowels.sort(reverse=True)
print('Sorted list (in Descending):', vowels)
Output:-
Sorted list: ['a', 'e', 'i', 'o', 'u']
Sorted list (in Descending): ['u', 'o', 'i', 'e', 'a']