28.10.2021 Views

Python Tutorial ( PDFDrive )

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Syntax

Following is the syntax for reverse() method:

list.reverse()

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 reverse() method.

#!/usr/bin/python

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

aList.reverse()

print "List : ", aList

Let us compile and run the above program, this will produce the following result:

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

list.sort([func])

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

• func -- This is an optional parameter, if given the it would use that function to sort the objects of the list..

Return Value

This method does not return any value but sort 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()

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!