Given a list of the elements and we have to sort the list in Ascending and the Descending order in Python.
Python list.sort() Method
sort() is a inbuilt method in Python, it is used to sort the elements/objects of the list in Ascending and Descending Order.
Sorting elements in Ascending Order (list.sort())
Syntax:
list.sort()
Program to sort list elements in Ascending Order
Output
Sorting in Descending Order (list.sort(reverse=True))
To sort a list in descending order, we pass reverse=True as an argument with sort() method.
Syntax:
Program to sort list elements in Descending Order
Output
need an explanation for this answer? contact us directly to get an explanation for this answer