Popping an element from the list

The pop() method enables removing an element from a specified position and return it:

    >>> index_list = [1, 2, 3, 4, 5, 6, 7]
>>> index_list.pop(3)
4
>>> index_list
[1, 2, 3, 5, 6, 7]

In this example, the index_list list consists of numbers between 1 and 7. When the third element is popped by passing the index position (3) as an argument, the number 4 is removed from the list and returned.

If no arguments are provided for the index position, the last element is popped and returned:

    >>> index_list.pop()
7
>>> index_list
[1, 2, 3, 5, 6]

In this example, the last element (7) was popped and returned.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.160.14