Hello and welcome to this utopia on python.
This Python lists and ordered sequins all elements.
And the list can contain a neat assortment of objects
undone.
Now we have discussed about data types such as indigenous clothes strings.
In this example here we have a variable e that refers to a memory location and this memory location
contains the value five the variable B refers to a memory location that contains the floating value.
Sixteen dot o the variability refers to a memory location that contains the string Python three dot
six coming to loose a list is an ordered sequence of objects and it can contain any arbitrary objects
such as integers loading by numbers and strings and each of the elements in a list are also called items
the items are separated by commas and finally the items are enclosed in square brackets and this is
known as the list.
So this list.
Be named as list one and a list is not merely a collection of objects.
It is an ordered collection of objects.
That means these are added in which we specify the elements.
When we define a list is the special characteristic of that particular list and this order is maintained
as long as the list is in the memory
say for example.
I change the order of the first two elements.
So here I have the floating point number.
And then an integer and then we have this string.
So in this case these two different lists even though the elements in both the list are the same.
So let's check this in the Jupiter note book.
So here I have my list.
The list is one which has three items.
Five the integer 5 and then the floating point number sixteen dot org.
And then a string by then three dot six.
Now if I want to know the memory location of the memory address to which this list is pointing to.
We use d i d function just as we used for those drawings and then integers.
So ideal in is the one.
So this is the memory location.
To which the variable LSD one is pointing to.
Now I'm going to change the positions of the first two items in the list so sixteen dot org is the first
element and then we have the integer and then the string by then three dot six.
So let's execute this set and then check the memory location.
So you can see once we have changed the the position of the elements the memory location has changed
so which means which means the order in which we specify the elements when we define a list is is the
characteristic of that particular list
let us now see how lists are stored in the memory.
So in our example that we have just considered we have defined debated in E which refers to the memory
address.
This is the memory address and this memory address contains divide to find Nick.
We then defined the relative in B which refers to the memory address.
And this particular memory address contains devalue sixteen dot o which is a floating point number and
then we have defined the word in C which refers to the memory address your and this memory address contains
devalue Python three dots six.
Now we have defined a list later.
Which refers to the memory address your and this memory location contained the address of each of the
elements in the list.
Say for example the first element in the list is the value five and the value five is contained in this
memory location.
So the memory location to which the list is binding to contains the address of the first element in
the list next.
The value sixteen dot or is contained in this memory location here.
So
here we have the address of the Element sixteen Dot.
Or next.
The third element is the string
but just contained in this memory location.
So yeah we have the address the string and finally as we know this memory location contains the value
five this one here contains the brand new sixteen dot or and this contains the string.
So this is how lists and other data types are stored in memory.
A list can contain any number of objects from zero to as many as your computer's memory of the number
and list objects need not be.
You'll need a given object again appeared in a list multiple times next list.
Mutable once a list has been created the elements can be added deleted shifted and moved around at will.
And by then belied a wide range of ways to modify this until now we have discussed about data types
such as integers loads and then strings and all of these data types are immutable but less mutable and
that add methods which can be applied on this which we will talk about and did in the later sections.
For now we will come to.
One method called the append method which append element to the end of the list so here we have a list
enlistees one that has the element five sixteen dawdle and python 3.0 6.
Now I have applied the method append on the list a list you run using D dot operator and I have POS
D argument code.
Now after this method is applied on the list the list will now be changed to include the element at
the end of the list then we assign say Bill X the value 10 that means X refers to a memory address that
contains derived Newton now.
Later I will change the value X from 10 to 7.
In this case what does already dead in the memory address is not changed but now x refers to a new memory
address which contains divide 7.
That means integers.
Immutable.
We cannot change any value that is on duty did in a particular memory Atlas coming to this.
This is the list that are defined a list D1 then which contains these three elements.
Five sixteen or and item three point six.
Now I have applied the append method on the list listing one after this has been applied.
The first position we have the integer 5 and then we have a floating by number and then as during and
after that the value horde has been appended to the list.
The data in the memory and address has been changed in case of Miss because lists are mutable.
So let us check the memory location before and after applying the append method on the list.
So here I have the list in one containing these three elements and Raven now call the the idea function
on the list listing one so this is D memory location to which a list to one is adapting to now let us
apply the append her no bias the argument for executed the same then we will display the missed it let's
do one so devalue.
Ford has been added to the end of the list and we will now check the memory atlas of the list a list.
One so as you can see here the memory address has not been changed but the data in the memory location
has been changed.
That is the value Ford has been added to the end of the list within the same memory address next element
in a list can be accessed individually using indexing and the individual elements in a list can be accessed
using an index in square brackets.
Say for example if we want to access the first element in the list the list u 1.
This is how we treat the element.
We place the index within square brackets.
This is similar to what we have done for strings next.
List indexing is zero based as it is with strings.
So the first element are the item in the list.
It is given an index Z or the next element has an index 1 to 3 and then so on
Biden allows negative indexing product sequences sequences such as strings and lists.
So LSD 1 0 minus 1 retrieves the last item in the list and trying to access an element.
Other than this will raise an index.
Edit the index must be an integer and we can't use a float or any other data type.
This will result in a type error.
So for example if we give the index as then this will throw an error because no element in the list
with the index 10.