Python List list() Method

Python 列表Python Lists


Description

The list() method is used to convert a tuple to a list.

Note:Tuples are very similar to lists, except that the element values of a tuple cannot be modified. Tuples are placed in parentheses, and lists are placed in square brackets.

Syntax

list() method syntax:

list( tup )

Parameters

  • tup -- The tuple to be converted to a list.

Return Value

Returns a list.

Example

The following example demonstrates how to use the list() function:

#!/usr/bin/python # -*- coding: UTF-8 -*- aTuple = (123, 'example', 'google', 'abc'); aList = list(aTuple) print ("List elements:") print(aList)

The output of the above example is as follows:

列表元素 : 
[123, 'example', 'google', 'abc']

Python 列表Python Lists

Other Extensions