This article mainly shares with you the detailed explanation of functions & methods in Python lists, hoping to help everyone.
Python list functions & methods
Python contains the following functions:
##Serial number | Function |
1 | cmp(list1, list2)Compare the elements of two lists
|
2 | len( list)Number of list elements
|
3 | max(list)Returns the maximum value of list elements
|
4 | min(list)Return the minimum value of the list element
|
5 | list(seq)Return the tuple Convert to list
|
Python contains the following methods:
Serial number |
Method |
1 |
list.append(obj) In the list Add a new object at the end |
2 |
list.count(obj) Count the number of times a certain element appears in the list |
3 |
list.extend(seq) Append multiple values from another sequence at one time to the end of the list (extend the original list with a new list) |
4 |
list.index(obj) Find the index position of the first matching item of a value from the list |
5 |
list.insert(index, obj) Insert objects into the list |
6 |
list.pop(obj=list[- 1]) Remove an element in the list (default is the last element) and return the value of the element |
7 |
list.remove(obj ) Remove the first occurrence of a value in the list |
8 |
list.reverse() Reverse elements in the list |
9 |
list.sort([func]) Sort the original list |
Related recommendations:
##Python list List
What you should know about the python list deduplication method
How to reference arrays in Python lists
The above is the detailed content of Detailed explanation of functions & methods in Python lists. For more information, please follow other related articles on the PHP Chinese website!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn