Home >>Python List Methods >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 | 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. |
a = ['Abhi', 'Mickey', 'Jerry', 'Cobra', 'Alpha']
a.sort()
print(a)
a = ['Abhi', 'Mickey', 'Jerry', 'Cobra', 'Alpha']
a.sort(reverse=True)
print(a)