Tutorials Point


  Python Basics
  Python Advanced
  Python Useful References
  Python Useful Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Python List sort() Method


previous next AddThis Social Bookmark Button


Description:

This method sorts objects of list, use compare func if given.

Syntax:

list.sort([func])

Parameters:

Here is the detail of parameters:

  • func: optional parameter, if given the it would use that function to sort the objects of the list.

Return Value:

It returns none but sort the given object from the list.

Example:

#!/usr/bin/python

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

aList.sort();
print "List : ", aList;

This will produce following result:

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


previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names