Python list sort – How to sort list in Python using sort() method

Python list length method

Python comes up with a very easy method to sort list. This method is sort()..

Syntax of sort method


Simple example of using sort Alphabetically

In example below sort method is used for an existing list. It will sort out list by alphabetical order.

Output will be

list before sorting=  [‘c’, ‘b’, ‘a’]

list after sorting=  [‘a’, ‘b’, ‘c’]

Sort Example with descending order

Output will be:

list before sorting=  [‘a’, ‘b’, ‘c’]

list after sorting=  [‘c’, ‘b’, ‘a’]

Example with numbers in descending order

list before sorting=  [10, 5, 6, 8]

list after sorting=  [10, 8, 6, 5]

Was this article helpful?

Related Articles

Leave A Comment?