28.10.2021 Views

Python Tutorial ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

list( seq )

Parameters

• seq -- This is a tuple to be converted into list.

Return Value

This method returns the list.

Example

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

!/usr/bin/python

aTuple = (123, 'xyz', 'zara', 'abc');

aList = list(aTuple)

print "List elements : ", aList

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

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

Python includes the following list methods:

SN

1

2

3

4

5

6

7

8

9

Methods with Description

list.append(obj)

Appends object obj to list

list.count(obj)

Returns count of how many times obj occurs in list

list.extend(seq)

Appends the contents of seq to list

list.index(obj)

Returns the lowest index in list that obj appears

list.insert(index, obj)

Inserts object obj into list at offset index

list.pop(obj=list[-1])

Removes and returns last object or obj from list

list.remove(obj)

Removes object obj from list

list.reverse()

Reverses objects of list in place

list.sort([func])

Sorts objects of list, use compare func if given

The methods are explained below:

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!