SoFunction
Updated on 2024-10-28

A simple tutorial on sorting in Python using the sort method

The sort() method sorts the objects in the list, comparing using func (if given).
grammatical

The following is the syntax of the sort() method:

([func])

parameters

  • func -- this is an optional parameter that will be used, if available, to sort the objects in the list

return value

This method does not return any value, but sorts the objects given from the list
(for) instance

The following example shows the use of the sort() method

#!/usr/bin/python

aList = [123, 'xyz', 'zara', 'abc', 'xyz'];

();
print "List : ", aList;

When we run the above program, it produces the following results:

List : [123, 'abc', 'xyz', 'xyz', 'zara']