Some of the list methods are mentioned in set 1 below
More methods are discussed in this article.
1. del[a : b] :- This method deletes all the elements in range starting from index ‘a’ till ‘b’ mentioned in arguments.
2. pop() :- This method deletes the element at the position mentioned in its arguments.
List elements after deleting are : 2 1 3 8 List elements after popping are : 2 1 8
3. insert(a, x) :- This function inserts an element at the position mentioned in its arguments. It takes 2 arguments, position and element to be added at respective position.
4. remove() :- This function is used to delete the first occurrence of number mentioned in its arguments.
List elements after inserting 4 are : 2 1 3 4 5 3 8 List elements after removing are : 2 1 4 5 3 8
5. sort() :- This function sorts the list in increasing order.
6. reverse() :- This function reverses the elements of list.
List elements after sorting are : 1 2 3 3 5 8 List elements after reversing are : 8 5 3 3 2 1
7. extend(b) :- This function is used to extend the list with the elements present in another list. This function takes another list as its argument.
8. clear() :- This function is used to erase all the elements of list. After this operation, list becomes empty.
List elements after extending are : 2 1 3 5 6 4 3 List elements after clearing are :
This article is contributed by Manjeet Singh .If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Python list | pop()
- List Methods in Python | Set 1 (in, not in, len(), min(), max()...)
- Python list | insert()
- Python | Insert the string at the beginning of all items in a list
- Python program to insert an element into sorted list
- Python | Insert after every Nth element in a list
- Python | Remove all values from a list present in other list
- Python | Sort the values of first list using second list
- Python | Sort list of list by specified index
- Python | Sort list according to other list order
- List methods in Python
- Python String Methods | Set 1 (find, rfind, startwith, endwith, islower, isupper, lower, upper, swapcase & title)
- Python String Methods | Set 2 (len, count, center, ljust, rjust, isalpha, isalnum, isspace & join)
- Dictionary Methods in Python | Set 1 (cmp(), len(), items()...)
- Dictionary Methods in Python | Set 2 (update(), has_key(), fromkeys()...)
- Python | Convert list of string to list of list
- Python | Convert list of tuples to list of list
- Add elements in start to sort the array | Variation of Stalin Sort
- List comprehension and ord() in Python to remove all characters other than alphabets
- Python Remove Duplicates from a List