Python List Methods
Naveen
- 1
The Python List is a general data structure widely used in Python programs.
They are both mutable and can be indexed and sliced.
![](https://www.nomidl.com/wp-content/uploads/2022/09/image-147.png)
List methods
1 – append(value)
Append a new element to the end of the list.
![](https://www.nomidl.com/wp-content/uploads/2022/09/image-148.png)
2 – extend(value)
Extends the list by appending elements from another enumerable.
![](https://www.nomidl.com/wp-content/uploads/2022/09/image-149.png)
3 – index(value)
Gets the index of the first occurrence of the input value. If the input value is not in the list a ValueError exception is raised.
![](https://www.nomidl.com/wp-content/uploads/2022/09/image-150.png)
4 – insert (index, value)
Inserts value just before the specifies index. Thus, after the insertion the new element occupies position index.
![](https://www.nomidl.com/wp-content/uploads/2022/09/image-151.png)
5 – pop([index])
Removes and returns the item at index. With no argument it removes and returns the last element of the list.
![](https://www.nomidl.com/wp-content/uploads/2022/09/image-152.png)
6 – remove (value)
Removes the list occurrence of the specified value. If the provided value cannot be found, a ValueError is raised.
![](https://www.nomidl.com/wp-content/uploads/2022/09/image-153.png)
7 – reverse()
Reverses the list in-place and return None.
![](https://www.nomidl.com/wp-content/uploads/2022/09/image-154.png)
8 – clear() – removes all items from the list
9 – count(value)
Counts the number of occurrences of some value in the list.
![](https://www.nomidl.com/wp-content/uploads/2022/09/image-155.png)
10 – sort() – sort the list
![](https://www.nomidl.com/wp-content/uploads/2022/09/image-156.png)
Popular Posts
Spread the knowledge
Some genuinely choice posts on this web site, saved to bookmarks.