Python3 Att List Pop
# Python3.x Python3 List pop() Method
[ Python3 Lists](#)
* * *
## Description
The pop() function is used to remove an element (by default, the last element) from a list and return its value.
## Syntax
The pop() method syntax:
list.pop()
## Parameters
* index -- Optional parameter, the index value of the list element to be removed. It cannot exceed the total length of the list. The default is index=-1, which deletes the last list value.
## Return Value
This method returns the removed element object from the list.
## Example
The following example demonstrates the usage of the pop() function:
## Example
#!/usr/bin/python3
list1 =['Google','Tutorial','Taobao']
list1.pop()
print("List now is : ", list1)
list1.pop(1)
print("List now is : ", list1)
The output of the above example is as follows:
List now is : ['Google', 'Tutorial']List now is : ['Google']
A queue is a First-In-First-Out (FIFO) data structure. We can use a list to implement the basic functionality of a queue.
* The `append()` method adds an element to the end of the queue.
* The `pop()` method removes and returns an element from the beginning of the queue.
## Example
queue =[]
# Add elements to the end of the queue
queue.append('A')
queue.append('B')
queue.append('C')
# Remove and return elements from the beginning of the queue
print(queue.pop(0))# A
print(queue.pop(0))# B
print(queue.pop(0))# C
In the example above, we created an empty list as a queue, then used the append() method to add three elements to the end of the queue. Next, we used the pop() method to remove and return elements from the beginning of the queue. Since a queue is a First-In-First-Out data structure, the output we get is 'A', 'B', and 'C'.
[ Python3 Lists](#)
YouTip