Most lists you create will be dynamic, meaning you will build a list and then add and remove elements
from it as your program runs its course.
For example, you might create a game in which your player has to shoot aliens out of the sky.
You could store the initial set of aliens in a list and or remove an alien from the list each time one
is shot down.
So each time a new alien appears on the screen, you add it to the list.
Your list of aliens will increase and decrease in length throughout the course of the game.
So now the syntax of for modifying an element is similar to the syntax for accessing an element.
Unless you change an element, you use the name of the list followed by the index index of the element
you want to change and then provide the new value and you want to item to have.
For example, say we have a list of course, topics.
On.
The first item in the list is car.
The car is not actually called subject name, right?
So we can change the value of this first item after the list has been created.
So now we will use the.
Course topics.
Right.
Power is the zeroth element.
Index is zero and we will make this car repair.
The car repair is actually like a course topic, right?
That's it.
So now we will print the.
Course.
Or let's actually print the.
Course Topics and index zero.
Let's print the car repair.
Right.
Let's know how it affected here.
As you can see here, car repair has changed.
Here we define the the course topics with.
Car.
Car as the first element.
And we change the value of the first item to car repair.
The output shows the first item has been changed while the rest of the list stays the same.
So you can change the value of any item in a list, not just the first item.
For example, let's.
2012.
So instead of it changing to car repair, we will make it.
Let's actually make it the.
Kotlin, right?
Kotlin.
Let's try it now.
And as you can see here, oops, We need to also change the print function because we are now seeing
the elements zero, not two.
And as you can see here, we have a Kotlin.
So also you want want to add a new element to a list for many reasons, right?
So, for example, you might want to make a new aliens this funny aliens to appear in a game.
Now you add a new data to a visualization or add a new registered users to make a website your build.
So Python provides several ways to add new data to existing lists.
So now let's let's start with the appending element.
So the end of the list, right?
So now we can also delete this alias here.
So here.
The simplest way to add a new element to a list here.
So the simplest way to add a new element to a list.
Is to append the item to the list.
So when you append an item to the list, the new element is added to the end of the list using the same
list we had in the previous example.
We will add a new element.
New element.
Let's make Kotlin or Swift Write.
So now we will write course topics.
Course Topics dot append.
Here we will enter the Kotlin.
Also we will make the course topics.
Course Topics that append Swift.
Swift.
And we will also have course topics that append.
C sharp or.
C-sharp here.
Now, what we're going to do is now there's a here.
So let's write that down what we have as a list.
So here we have item 012.
Pray for.
One, two, three, four, five.
Of let's make it.
Let's actually make it from here.
Zero one, two, three, four.
Five.
Thanks.
One, two.
Three, four, five, six, seven.
Here.
And seven.
So here we will make this like that.
Here.
So.
In first list.
Remember, we had the.
Actually here.
So in verses we have car right?
Car.
Are.
The first is Kotlin.
I will make it short.
Kotlin or Android.
Here A and.
Here and Java here.
Var python.
And digital forensics DVR.
I will make it short here.
Was.
He.
Are digital forensics.
And here remember we added here items, right?
So these items were Kotlin.
So remember, Kotlin added first year.
So after this we are adding Kotlin.
So the Kotlin will be added first.
In this case, it's going to be Remember what?
Remember?
Yeah.
Kotlin is going to be fifth item on the list index.
But.
Lynn.
Or no?
Yes.
Kotlin here.
And we also have the swift here.
It's gonna it's added secondly.
So are we going to make it six item?
We're.
Because as you remember here, this function appends at the end of the list.
So if you Kotlin ends here, here, Kotlin is here.
After that, we are adding sweat.
So Cutlan Swift is after Kotlin and we add the C sharp because C sharp is after the swift.
So.
And we also have C sharp here.
That's it.
Here we add the append method.
Add three items to the end of the list without affecting any other elements in the list.
So the append method makes it easy to build the list dynamically.
For example, you can start with an empty list and then add items to the list using series of append
calls using an empty list.
Let's add the elements to our core, to our list here.
So now let me look at the first lecture.
Yeah, that's okay.
So now we will instead of this, we will add and also use this here.
So now we will create a new list.
Actually, let's actually, instead of let's print the list course topics to show you what changed.
Seven.
And as you can see, it's C-sharp.
Six is swift.
The fifth is Kotlin.
The fourth is.
And as you can see, these are not changed.
Affected by the change.
These are not here.
And as you can see, one.
Lastly, zero.
Now.
I will take this note here and I will share this file with you.
Now here we will delete these quotes here and instead we will add course.
Or let's actually course names, right?
Course names or courses here.
Oxley Courses.
And here we will make the list.
Right.
So.
If you do write this code, this will create the.
This will.
I'm sorry.
So this will create.
Empty list.
This will create an empty list here and you can add or delete later.
So now, since we created this, the append method makes it easy to build list dynamically.
So now we will use auxiliary courses.
So the courses that append, we will add new course.
Right?
Android Kotlin training in 33 hours.
And here after that we will Oxley courses that append Python training best Python course in the world.
Right?
In the world.
The excellent courses that are pending.
Ethical hacking with Python in 20 hours.
Oxley.
Oxley courses that append and we will make.
It's actually right.
Designing.
Database models with my SQL.
That's it.
Now we will write print this down.
Here.
Let's print.
Oxer the courses and one.
Best courses in the world, best Python courses in the world.
This is the first year.
So actually this number is zero one.
Two.
Three.
Now we will write zero under coding training in 33 hours.
One Python course in the world.
Two Ethical hacking with Python and 20 hours three designing database models with MySQL.
So building list this way is very common because you often want to know the data your users want to
store in a program until after the program is running, right?
So to put your users in control, start by defining an empty list that still hold the user's value.
Then append each new value provided to the list you just created here.