Python List Function:
|We can use the PyCharm code editor for this example. If you do not know about it then follow this link- How to install PyCharm for Python and create a program in it.|
(1) del– The keyword del can remove a specified item from the list using items indexed number.
(2) pop()– Returns the element whose index is passed as a parameter to this function and also removes it from the list. If no parameter is given, then it returns and removes the last element of the list.
The pop() method returns the removed value as shown below.
(3) remove()– Removes the given element from the list. If the element is present multiple times, only the first occurrence is removed. If the element is not present, then ValueError is generated.
(4) clear()– The clear() function can be used to clear items from a list.
(5) Update Element From List– By using this function you can update any value in the list by using the index number.
(6) insert()– Inserts an element at a particular index in the list.
(7) append()– Items can be added to the end of a list using the append() function.
Another example is shown below-
(8) extend()– Items from one list can be appended to another list using the extend() function.
(9) zip()– The zip function takes two lists and “zips” them together, matching the first item from the list1 with the first item from the list2, and so on.
- Note: If one list contains more values than the other list. In that case, the zip function returns only the same number of values ignoring the extra value in the list, as shown below.
Another method to Iterate Two Lists:
|List Comprehension in Python|
List Iteration in Python
String Iteration in Python
String Indexing and String Slicing in Python
Python Identity Operators
Python (programming language)– Wikipedia