Home >>Python List Methods >Python List sort() Method

Python List sort() Method

Python List sort() Method

Python list sort() method is used to sort the given input list in ascending order by default.

Syntax:
list.sort(reverse, key)

Parameter Values

Parameter Description
reverse This is an optional parameter. If it is True then it will sort the list descending. By default it is False.
key This is an optional parameter. It defines a function to specify the sorting criteria.
Here is an example of Python sort() method:

a = ['Abhi', 'Mickey', 'Jerry', 'Cobra', 'Alpha']
a.sort()
print(a)

Output:
['Abhi', 'Alpha', 'Cobra', 'Jerry', 'Mickey']
Example 2:

a = ['Abhi', 'Mickey', 'Jerry', 'Cobra', 'Alpha']
a.sort(reverse=True)
print(a)

Output:
['Mickey', 'Jerry', 'Cobra', 'Alpha', 'Abhi']

No Sidebar ads