Sometimes you will want to use the value of an item after you remove it from a list.
For example, you might want to get the A and B position of an alien that was just shot down so you
can draw an explosion at that position.
So in a web application, you might want to remove a user from a list of active members and then add
that user to a list of inactive members.
So the Pope method removes the last item in a list, but it lets you work with that item after removing
it.
So the term pope comes from thinking of a list as a stack of items and popping one of the item off the
top of the stack.
So in this analogy, the top of stack corresponds to the end of the list.
So let's pop a pop.
Let's actually use the car models right now.
Let's use the car models.
Let's delete all of this.
We will create the car models, so car models here.
So we will make the BMW Mercedes.
So Toyota.
And Suzuki.
Right?
After that, we will print our car models, and after that we will pop, pop car models here.
Pop.
Models.
And here we will add the car models that pop.
So after that, we will print the car models.
Car models.
And after that, we will print the pop car models as well.
That's it.
Now let's run the code.
And here.
So we start by defining and printing the list of car models.
Then we pop a value from the list.
Let's actually connect them.
So this is the first.
So this is the.
I'm sorry.
Let's let me fix that.
So this is the first code and this is the first code here.
This is the second print statement.
This is the second print statement here.
And this is the third.
This is the third print statement.
And here we start by defining and printing the list of car models.
And after that, then we pop a value from the list with this command.
Here we pop a value from the list.
That's it.
Uh, with, uh, with this pop comment here.
Right.
And after that.
So.
And assign that value to the variable.
So we are assigning this port here to this newly created port car models variable.
And then we print the port variable.
So firstly, we print a list to show that the value has been removed from the list with this.
Uh, with this line of code here.
And after that.
After that, we print the list.
We print the popped value here.
This is the popped value here.
Then we print the popped value here.
That's it.
This is the value that has been removed from the list.
Value.
Value removed.
Remove.
So in this case.
This popped car models is not list so not.
List, right?
This is just a variable that's popped from the car models.
In this case, the last one was Suzuki, so the Suzuki was popped from.
This list and the output shows that the value susuki was removed from the end of the list and is now
assigned to the variable popped car models.
That's it.
But here in this list, the new new car model list, we don't have Suzuki anymore here, so how might
this pop method be useful?
Right?
Imagine that the car models in the list are stored in a chronological order according to when we owned
them.
So if this is the case, we can use the pop method to print a statement about last car model we bought.
And the output is simple sentence about the most recent motorcycle here.
So now let's actually create that output now and I think we can delete delete this drawing now.
I hope this helped us help helped you to understand how the logic works here with this pop here and
now.
We will pop.
We will firstly.
Right.
So.
We have.
Car models and let's actually delete this, our old code now.
And we already created the car models list.
We will do something a bit different here.
So last owned or.
Yeah, last on this.
Okay.
And here we will motorcycles, car models that pop here.
As you remember, this will take the Suzuki down here.
So now we will pop the Suzuki here.
And after that print the F here, we will also we will use format here.
So now the last car, The last car, last.
I'm sorry for the ticking of the keyboard.
So the last.
Car model.
Model.
I owned was a and here we are adding the last owned right last on last owned that title in case we don't
have the title here.
So the first letter uppercase we will write it like so it will look nice, right?
And that's it.
Now we will run this.
And as you can see here, the last car model I owned was a Suzuki.