List (list) is the most frequently used data type in Python.
#List can complete the data structure implementation of most collection classes. It supports characters, numbers, strings and can even contain lists (i.e. nested). (Recommended learning: Python video tutorial)
Lists are marked with [ ] and are the most common composite data type in Python.
The variable [head subscript: tail subscript] can also be used to cut the values in the list, and the corresponding list can be intercepted. The index from left to right starts with the default 0, and the index from right to left defaults to -1. At the beginning, the subscript can be empty to indicate getting to the beginning or end.
list() method is used to convert a tuple into a list.
Note: Tuples and lists are very similar. The difference is that the element values of tuples cannot be modified. Tuples are placed in brackets, and lists are placed in square brackets.
list() method syntax:
list( tup )
Parameters
tup -- The tuple to be converted to a list.
Return value
Return list.
Examples
The following examples show how to use the list() function:
#!/usr/bin/python # -*- coding: UTF-8 -*- aTuple = (123, 'xyz', 'zara', 'abc'); aList = list(aTuple) print "列表元素 : ", aList
The output results of the above examples are as follows:
列表元素 : [123, 'xyz', 'zara', 'abc']
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to use list function in python. For more information, please follow other related articles on the PHP Chinese website!