In this tutorial, we will see about Python List‘s pop method.Python List pop method is used to remove and return the element at specified index.
Python List insert syntax
here list1 is object of list.
Python List pop example
You can simply use pop method to remove and return element at given index.If you do not pass anyparameter then it will remove and return last element in the list.
Let’s understand this with the help of simple example.
listOfVehicles=['Car','Bike','Cycle','Truck'] #Let's remove bike from above list vehicleRemoved=listOfVehicles.pop(1) print("listOfVehicles:",listOfVehicles) print("Removed vehicle:",vehicleRemoved) #Let's use pop method without any argument, it will delete last element by default vehicleRemoved=listOfVehicles.pop() print("listOfVehicles:",listOfVehicles) print("Removed vehicle:",vehicleRemoved)
Removed vehicle: Bike
listOfVehicles: [‘Car’, ‘Cycle’]
Removed vehicle: Truck
As you can see here, if we do not pass any paramter, then pop method will remove last element from the list.
That’s all about Python List pop method.