Python List Function

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.

del function python

(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.

pop method in python

The pop() method returns the removed value as shown below.

pop() method return removed value

(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.

remove method python

(4) clear() The clear() function can be used to clear items from a list.

clear function in python

(5) Update Element From List By using this function you can update any value in the list by using the index number.

Update Element From List Python

(6) insert() Inserts an element at a particular index in the list.

insert function in python

(7) append()– Items can be added to the end of a list using the append() function.

python append function

Another example is shown below-

append function in python

(8) extend() Items from one list can be appended to another list using the extend() function.

python 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.

python zip function
  • 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.
zip function in python

Another method to Iterate Two Lists:

Iterate Two Lists in python

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

Comments (No)

Leave a Reply