Hello and welcome to this lecture in this lecture we're going to learn about the tuple.
So if you this remember we have done much of the that a study says now.
So if you just remember we have done the first fundamental data type that is a string which is the collection
of numbers or real characters basically.
So this was a sequence of characters which we'd call this string and the next one was a list which was
created by this square bracket.
And the next one was the discovery which was created with the Scally braces.
Now if you remember the next thing was left with only the parents.
So say it or to police only those thing that is created with this brackets panties.
So if you see or did the type of that back it or if he was assigned something maybe this empty parenthesis
and if you take the type of this a it is going to source that diabetes tuple because we have created
our empty tuple over here.
So this tuple is similar to that of least about the difference between the list and the tuple is that
it is very important just remember that we can not change the element of the tuple once it is assigned
but in the least element it can be tense.
So that is the main difference between the list and the tuple.
So if we just assign some element to the tuple it cannot be changed but in the case of list we have
already seen we can just manually list whatever whichever way we want.
So first of all let's see how we can describe the tuple how to manipulate the tuple first.
And so let me create my tuple and in this tuple I want to assign.
So I have already seen you that the table is created with this pen and this is so you can just assign
the element like this.
So now you have created your own tuple.
So this is the way to create the tuple so tuple can be created with the mix that data type 2.
So if you say that I want to assign maybe the integer maybe this string are maybe the decimal float
which you call or maybe the boolean.
This is all valid.
So if you take the tuple if it is created or not so you can see our tuple has been created with the
mixed data types.
You can also have the nested tuples so you can see I look right now nested tuple.
So first of all let me say get is the first element and now I want to just have the multiple that I
doctors over here first one this list and the next one is simply there not the tuple so you can do this.
So if you take your tuple again then you could see that to have created successfully the new tuple with
the nested tuple in it which is the one single tuple inside our main tuple.
So let's see now how we can this is the element from the tuple.
So if you just remember in the case of the list and this string we used to do it with the index.
So same IDs in the case of the tuple.
So if you want maybe the element out then you will simply pass your data and you'll see that card has
been popped out as the first element of that tuple and if you want to get maybe this six element of
the list then first of all you have to get this whole list which is obviously at the index one and the
next index or to be again one because this inside this list this is the delta position.
This is first put this in.
So that means if I just it into you are getting the six which is basically this middle element of that
first index at least if you won this party element what you can do is simply you can say my tuple and
you can simply pass first that is a two.
And now the second index can be either the minus one because if you just remember the last element can
be always index with the minus one or it can be something like you can count from here and this is at
0.
This is at 1 and this is it too.
So if you as a spicier again the two it is also valid.
So tuple also have the negative indexing so you can see here that if you just do something like My tuple
and if you want the whole tuple of this whole tuple then you can simply get the minus one which the
negative indexing and you'll see a whole tuple will pop out over here is output that means it will support
the negative indexing too.
So let me just clear this real quick and let me stop you some more about the tuple so let's create that
same tuple again.
And now what we need to learn is about the slicing and we have learned about the slicing and previous
couple of lectures in the case of police standing the case of a string to it but for now let's see how
we can this this is our slice the part of the tuple if I want maybe from this card.
So okay let's make another tuple which will be more meaningful.
So you know how to create the tuple as a b c..
Okay.
The next one would be D
Yeah and you have.
Last one ready.
So let's make this tuple so let's see how slicing works in the tuple.
It is similar to that of least as I will it is solely in the previous Lexus.
So first of all let me say I want to slice this part from B to may be from B to E..
So let's count for the index first.
So is there 0.
So we went from B that means we have to this include from one end.
Just remember this is the inclusion bodies and if you do something like two that means from C it will
include.
And if I just do one it will include from perdition this which is I went from B to maybe D Okay.
Prom let me just do something like from B to D.
So that means this is the inclusion is and I want the deal.
So that means we have to put here the position of we are the index of the.
So that means the index of these it two three four.
If I put forward here that means I'm going to get.
Okay I'm going to get B C D but if I do something like My tuple and if I just want a b c d if I weren't
B C D but I just made one two three.
If I just put the poses one of only D then you are going to get b c only.
So this is the exclusion put.
So just remember that it is same for the list and it is also similar for the case of a string and similar
for the case of a d tuple if you want everything from beginning to end.
You can do simply is simply do this and you'll get hold of tuple if you don't pass anything over here
it is going to loop from beginning to the end with a step of one.
So this is the way to slice your tuple which is the interesting part of the any that I Stokes's.
So next thing what I want you to soil is let me make some program over here.
So let's go in our script to endless.
Make some program over here so let's see if I just make dignity.
This is our dignity and as a name is Python and work is for.
Let me say programmer so if this is our this name and if I say for I in r basically for key value in
this and if I use this one to bring this maybe by formatting is read this way I want to format maybe
with the key and the value so how this work and we are pruning over here so let's see how this works.
Let's take this first Alice print displacing a 5 it is going to so I see there are too many values to
unpack so if we just remember we have learned this name in the previous lectures but I haven't told
you one thing that is this this is not terrible.
So you cannot loop through this for loop is not going to work in the case of dysentery but if you convert
this dignity into the tuple with these items method let's say this items matter unless less this and
place up five then this is going to work.
So what is happening over here is let me show you.
So at first we are creating the dignity which is obviously you can see in here which is this this with
a gay envelope here and now we want to look.
This is dysentery and we are looping with this for loop with a key and value that means this name will
be key.
This python will be value for the first loop in the second loop this scheme will be work value will
be program.
That was our intention but this is the dysentery and this Nadi cannot be terrible.
So just remember that we cannot loop in the dictionary.
But if you convert this this Nadi into the tuple or into the list then it is terrible.
So normally in the case of real world programming we normally convert this dysentery into the tuple
so as to loop in the tuple.
So if you want to loop in this dysentery you will simply call these items method in the this area which
is going to this convert this dignity into the tuple and in the Tupelo you can Kansas loop and if you
see the result over here we can see that we have now the result.
So if I saw you over here let's copy this story go back pasted over here.
And if I say that items then you will see that this lady has been converted into the tuple now which
is having this tuple so you can see clearly.
But here it is also that this nearly object.
But it has converted into this tuple.
So this is first tuple.
This is second tuple.
So now we can just loop in this tuple form these for loop and where this formatting would be invaluable.
So this is the way to convert the native from the dis needed to the tuples so as to work with the for
loop or to make it either tables.
So this way the part of the tuples or that is Texas is in there the way up will learn about object oriented
programming in the next lecture.
See in the next one.