반응형

Python List sort() Method


* 오름차순이 .sort(), 내림차순은 .sort(reverse=True)


Description

The method sort() sorts objects of list, use compare func if given.

Syntax

Following is the syntax for sort() method −

list.sort([func])

Parameters

NA

Return Value

This method does not return any value but reverse the given object from the list.

Example

The following example shows the usage of sort() method.

#!/usr/bin/python

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

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

When we run above program, it produces following result −

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


반응형

+ Recent posts