WEBVTT

00:00.170 --> 00:00.860
Hello guys.

00:00.860 --> 00:03.560
So we are going to continue the discussion with respect to Python.

00:03.560 --> 00:07.940
And in this video we are going to discuss about our next data structure, which is called as tuples.

00:07.970 --> 00:13.370
Already in our previous video we have seen about list and we had written a lot of code.

00:13.400 --> 00:18.380
You know, if you probably I go ahead and show you we had written somewhere around 54 lines of code.

00:18.380 --> 00:20.330
We understood about list comprehension.

00:20.330 --> 00:23.600
We saw different different methods, operations and many more things.

00:23.600 --> 00:27.380
Now, uh, in this session, what all things we are going to discuss.

00:27.380 --> 00:31.010
So I have actually given you the brief outline of the video.

00:31.010 --> 00:35.870
First of all, we are going to understand about tuples, how to create tuples, accessing tuple elements,

00:35.870 --> 00:37.340
tuple operation.

00:37.340 --> 00:40.070
What is this immutable nature of tuples.

00:40.070 --> 00:44.540
And what are some of the, uh tuples common tuple methods that are used.

00:44.540 --> 00:48.950
How to pack and unpack tuples, nested tuples and all these things.

00:48.950 --> 00:51.440
We are going to see with a lot of practical example.

00:51.470 --> 00:57.020
Now before I go ahead, first of all, let me just give you a small definition about tuples.

00:57.020 --> 00:57.410
Right.

00:57.410 --> 01:02.040
So tuples are ordered collection of items that are immutable.

01:02.070 --> 01:02.490
Right.

01:02.490 --> 01:06.480
So we'll understand about this particular meaning, which is called as immutable.

01:06.480 --> 01:09.660
If I talk about list, it is an ordered collection of items.

01:09.660 --> 01:13.710
And the items can be of any type and they are mutable, right.

01:13.710 --> 01:16.200
But here it is something like immutable.

01:16.200 --> 01:18.120
They are similar to list, but they are immutable.

01:18.360 --> 01:20.850
They are immutability makes them different.

01:20.880 --> 01:25.110
Now first of all, we'll try to understand how to go ahead and create a tuple.

01:25.110 --> 01:32.100
So for creating a tuple right we have to just use this two empty brackets.

01:32.100 --> 01:34.560
So let me just go ahead and write it over here.

01:34.560 --> 01:36.930
So this is my empty tuple okay.

01:36.960 --> 01:41.370
And just by using this two brackets right I will be able to create it.

01:41.400 --> 01:41.820
Right.

01:41.820 --> 01:48.270
And if I go ahead and display the print uh let me first of all print this empty tuple.

01:48.270 --> 01:53.580
And then we will also go ahead and display our type of this particular empty tuple.

01:54.090 --> 01:54.660
Okay.

01:54.750 --> 01:56.640
So here you have this.

01:56.640 --> 02:01.210
If I execute this you can see this is an empty tuple that is getting created in list.

02:01.240 --> 02:02.770
We use two square brackets.

02:02.770 --> 02:05.080
In this we are just using this rounded brackets.

02:05.110 --> 02:05.500
Right.

02:05.500 --> 02:09.760
And then over here you can see that I'm getting an empty tuple which is completely empty.

02:09.760 --> 02:14.590
And if I go ahead and see the type of empty tuple, it is nothing but tuple itself, right?

02:14.620 --> 02:17.230
Now if I probably consider list right.

02:17.230 --> 02:19.780
So list if I also use like this.

02:19.780 --> 02:20.200
Right.

02:20.200 --> 02:22.240
And if I go ahead and create an empty list.

02:22.240 --> 02:25.570
So I can also use this class directly and create an empty list.

02:25.600 --> 02:28.060
Okay, so this I missed in my previous video.

02:28.060 --> 02:30.610
So I'm just going to show it over here.

02:30.610 --> 02:36.370
And similarly if I want to probably create a tuple, let's say this is my tuple, I can actually go

02:36.400 --> 02:40.540
ahead and use the same type of class and create an empty tuple.

02:40.540 --> 02:45.190
So both the ways I'm actually trying to show you so that you understand both these ways.

02:45.220 --> 02:45.610
Right.

02:45.610 --> 02:50.740
So here you can see when I'm seeing the type of this, this will be an list and this will be tuple.

02:50.770 --> 02:51.040
Right.

02:51.040 --> 02:57.650
So you can also use this uh method in order to create an empty list or tuples.

02:57.680 --> 03:00.170
Okay inside this also I can put up elements.

03:00.170 --> 03:01.820
It is up to us right now.

03:01.820 --> 03:06.710
Let me go ahead and add some elements into this particular tuple okay.

03:06.740 --> 03:09.050
Now how do I add this particular elements.

03:09.050 --> 03:11.210
Uh uh inside this particular tuple.

03:11.210 --> 03:12.530
And uh how to do that.

03:12.560 --> 03:13.790
We'll be seeing a lot of methods.

03:13.790 --> 03:17.720
But here what I'm actually going to do, let me just go ahead and directly create a tuple.

03:17.720 --> 03:21.350
And if I go ahead and write tuple okay.

03:21.350 --> 03:25.880
And here I can actually give a list like 123456 okay.

03:25.880 --> 03:29.000
And now this list will get basically get converted into a tuple.

03:29.000 --> 03:34.310
So if I go ahead and display this numbers here, you can see that I'm actually getting a tuple right.

03:34.310 --> 03:37.760
So that basically means a list can be converted to a tuple.

03:37.760 --> 03:40.130
And even a tuple can be converted to a list.

03:40.160 --> 03:40.430
Right.

03:40.460 --> 03:45.290
So if I go ahead and basically write like this 123456.

03:45.290 --> 03:45.500
Right.

03:45.530 --> 03:48.200
So this is my uh tuple itself.

03:48.200 --> 03:51.830
And now if I go ahead and write list and I close this particular bracket.

03:51.830 --> 03:55.820
So here you'll be able to see that I'm able to get a list right list of elements.

03:55.820 --> 03:59.220
So both of the ways you can basically do the type conversion.

03:59.250 --> 03:59.670
Okay.

03:59.700 --> 04:05.820
Now as I said, uh, in tuples also you can let's say I'm going to probably go ahead and create my mixed

04:05.820 --> 04:06.900
tuple here.

04:06.900 --> 04:09.540
Also you can use different different data type elements.

04:09.570 --> 04:15.930
Let's say I want to use numerical I want to probably use string I want to go ahead and use a floating

04:15.930 --> 04:16.680
point number.

04:16.680 --> 04:19.440
I can also go ahead and use my boolean variable.

04:19.470 --> 04:19.800
Right.

04:19.800 --> 04:24.930
So now if I go ahead and print this then also this will get uh created.

04:24.930 --> 04:26.610
The tuple will basically get created.

04:26.640 --> 04:27.180
Okay.

04:27.240 --> 04:32.880
Now this is uh a basic information about tuple, how you can actually create and how you can proceed.

04:32.910 --> 04:33.390
Okay.

04:33.420 --> 04:35.400
Now let me do one thing quickly.

04:35.400 --> 04:40.050
Let me go ahead and explain you about the next thing that we are going to discuss.

04:40.080 --> 04:42.900
It is nothing but accessing tuple elements.

04:42.930 --> 04:43.500
Okay.

04:43.620 --> 04:45.480
Now for accessing tuple elements.

04:45.480 --> 04:48.120
What all things we really need to do that we will be discussing.

04:48.150 --> 04:48.390
Okay.

04:48.420 --> 04:50.490
Like I want to pick up any elements as such.

04:50.490 --> 04:52.260
So right now let me just go ahead and see.

04:52.260 --> 04:53.280
This is my numbers.

04:53.310 --> 04:55.750
Now here you can see that this is in the form of tuples.

04:55.750 --> 04:56.980
I have six elements.

04:56.980 --> 05:00.880
Let's say I go ahead and write numbers of zero okay.

05:00.910 --> 05:04.270
Or let me just go ahead and write it in the in line next line.

05:04.270 --> 05:06.370
So if I go ahead and write numbers of zero.

05:06.370 --> 05:09.310
So here I'll be able to see first element over here.

05:09.310 --> 05:10.870
This is my first zeroth index.

05:10.870 --> 05:12.370
I'm able to see it over here.

05:12.370 --> 05:14.110
Then I have two over here.

05:14.110 --> 05:14.320
Also.

05:14.320 --> 05:16.630
You can see I'm able to pick up these elements right.

05:16.660 --> 05:22.540
Similarly, if I go ahead and let's say that I'm just going to print this okay I want to pick up the

05:22.540 --> 05:23.980
last element okay.

05:24.010 --> 05:25.090
Last element.

05:25.090 --> 05:29.920
Either you can directly write the index or what I'm actually going to do, I'm just going to use minus

05:29.920 --> 05:30.190
one.

05:30.220 --> 05:30.430
Right.

05:30.460 --> 05:33.550
So I'll be able to get the last elements again.

05:33.640 --> 05:36.100
The indexing will be almost similar like a list.

05:36.130 --> 05:39.280
Even the slicing operation will be also similar like a list.

05:39.310 --> 05:46.030
Okay, so let's say I go ahead and write numbers and here I'll write zero colon four.

05:46.060 --> 05:49.990
That basically means I'll be able to get the element between zero index to the third index.

05:49.990 --> 05:52.870
So same slicing operation whatever things we have actually discussed.

05:52.900 --> 05:58.220
Similarly, if I go ahead and write numbers with double colon, right, I'll be able to see it.

05:58.220 --> 06:03.350
If I go ahead and write double colon minus one, I'll be able to get the reverse of all the tuple values

06:03.350 --> 06:05.840
right, but the return type will be always tuple.

06:05.870 --> 06:06.380
Okay.

06:06.380 --> 06:11.630
So all the indexing and slicing operation that we have actually done with the help of list.

06:12.080 --> 06:14.690
Similarly you can actually do it with the help of tuples.

06:14.720 --> 06:15.200
Okay.

06:15.230 --> 06:22.160
Then let's go ahead and see tuples operation tuple operations okay.

06:22.250 --> 06:28.730
Now tuple supports various operations like concatenation repetition and slicing okay.

06:28.730 --> 06:30.470
So we'll be discussing about that.

06:30.470 --> 06:33.980
Let's say I have numbers one tuple okay.

06:33.980 --> 06:38.480
And I had also created another tuple which is called as mixed tuple.

06:38.510 --> 06:38.810
Right.

06:38.810 --> 06:41.000
So this were the elements right.

06:41.030 --> 06:45.170
Now what if I just go ahead and write something like this.

06:45.170 --> 06:47.900
Numbers plus mixed tuple okay.

06:47.930 --> 06:51.260
So here in short this is an arithmetic operation.

06:51.260 --> 06:56.610
But since we have two pupils over here, I will definitely say this as a concatenation, right?

06:56.640 --> 06:59.160
Concatenation basically means combining two things, right?

06:59.190 --> 07:04.200
So here you'll be able to see I will just go ahead and write concatenation underscore tuple.

07:04.200 --> 07:06.660
And I will just go ahead and concatenate this.

07:06.660 --> 07:10.770
Now if I go ahead and print this concatenation right.

07:10.800 --> 07:15.450
Concatenation tuple you'll be able to see that I will be getting something like this.

07:15.450 --> 07:18.990
Now all this tuple both the elements of this particular tuple has been combined.

07:19.020 --> 07:23.580
So I have 123456 then one hello world 3.14 and two okay.

07:23.610 --> 07:27.390
Now let's say that I want to perform some more operations.

07:27.420 --> 07:27.600
Right.

07:27.630 --> 07:31.650
Let's say I want to go ahead and write something like this okay.

07:31.920 --> 07:34.560
Or repeated or let me do one thing.

07:34.560 --> 07:36.600
Let me just go ahead and create this.

07:37.770 --> 07:41.430
So I will just go ahead and do okay.

07:41.460 --> 07:44.940
Or I'll take this mixed tuple okay.

07:44.940 --> 07:47.880
And I will just try to multiply with an operation three.

07:47.910 --> 07:49.230
Now see what will happen.

07:49.230 --> 07:52.150
So here you can see mixed tuple had one.

07:52.180 --> 07:53.860
Hello world 3.14 and true.

07:53.890 --> 07:57.130
Now this has got entirely repeated three times, right?

07:57.130 --> 08:02.230
So in this kind of multiplication operation, what is basically happening is that the entire tuple is

08:02.230 --> 08:04.270
basically getting appended three times.

08:04.270 --> 08:04.840
Right.

08:04.900 --> 08:08.200
So that that is the reason we are basically doing an operation over here.

08:08.200 --> 08:14.020
So uh, so this is what is something different with respect to the calculation that we do.

08:14.050 --> 08:18.820
Now you may be thinking, Krish, what about if I try to do this with numbers right.

08:18.850 --> 08:20.350
Numbers multiplied by three.

08:20.380 --> 08:22.270
So here also the same thing will happen.

08:22.270 --> 08:24.310
So 123456123456.

08:24.310 --> 08:25.600
And 123456.

08:25.600 --> 08:31.210
You may be thinking, Krish, wasn't it like you have to probably multiply all these numbers that also

08:31.210 --> 08:35.890
we can do it, but we have to iterate it inside this particular tuple, get each element and then perform

08:35.890 --> 08:36.940
the numerical operation.

08:36.970 --> 08:37.360
Okay.

08:37.390 --> 08:42.730
But right now with respect to generic concatenation and this kind of operation here you can see that

08:42.730 --> 08:47.950
three times n number of times based on this multiplication that we are doing that many number of times,

08:47.950 --> 08:51.350
this tuple will get appended with respect to the element.

08:51.380 --> 08:51.920
Okay.

08:52.130 --> 08:54.410
So these are some of the basic operations.

08:54.500 --> 09:00.260
Now let's go ahead and discuss about immutable nature of tuples.

09:00.290 --> 09:00.740
Okay.

09:00.770 --> 09:03.860
This is important of tuples.

09:04.610 --> 09:09.680
Now in the immutable nature of tuples you need to understand one thing.

09:09.890 --> 09:13.040
And that is the first point that we have already learned right.

09:13.070 --> 09:16.520
Tuples are immutable okay.

09:16.550 --> 09:19.130
Meaning the elements cannot be changed once assigned.

09:19.160 --> 09:19.460
Okay.

09:19.490 --> 09:24.170
Let's say that I go ahead and create my list and I go ahead and write one, 234, five.

09:24.200 --> 09:24.620
Right.

09:24.650 --> 09:26.120
Now let me do one thing.

09:26.120 --> 09:27.320
List of zero.

09:28.340 --> 09:34.820
Or if I go ahead and print this specific list I will be okay.

09:34.850 --> 09:35.540
There is an error.

09:35.570 --> 09:36.350
Don't worry.

09:36.860 --> 09:37.310
Okay.

09:37.310 --> 09:39.620
So here you can see I'll be getting this specific element.

09:39.650 --> 09:41.630
Now let's see this okay.

09:41.660 --> 09:46.670
Now what I will do I will go ahead and take the first index and replace with it.

09:46.700 --> 09:47.870
Krish okay.

09:48.380 --> 09:49.950
Now I'll go ahead and print the list.

09:49.980 --> 09:51.360
Now see what will happen.

09:51.390 --> 09:53.310
So here we are changing the element.

09:53.310 --> 09:58.110
And this second index or this first index element has got replaced with crush.

09:58.140 --> 10:01.500
So this basically means list are mutable.

10:01.500 --> 10:04.530
That basically means the element can be changed once assigned.

10:04.620 --> 10:06.120
Now similar operation.

10:06.120 --> 10:10.140
If I try to do with the same numbers that we had, write in the form of tuple.

10:10.140 --> 10:13.470
If I go ahead and say hey, number of one, what is the number of one two?

10:13.500 --> 10:17.820
If I try to assign some value, let's say I try to assign a value called as crush.

10:17.850 --> 10:22.170
Here it says that hey tuple object does not support item assignment.

10:22.170 --> 10:26.580
And this is what immutable immutability comes into picture.

10:26.910 --> 10:28.590
Tuples are immutable.

10:28.590 --> 10:30.720
The elements cannot be changed once assigned.

10:30.750 --> 10:31.050
Okay.

10:31.080 --> 10:35.010
So here you can actually see what I exactly mean to say.

10:35.010 --> 10:35.460
Right.

10:35.460 --> 10:37.140
And this is very much important.

10:37.140 --> 10:41.940
That basically means once you have defined a tuple you cannot change the element inside that okay.

10:41.970 --> 10:45.030
Once it is assigned there are ways how you can do it.

10:45.030 --> 10:50.170
First of all, you can take the tuple, convert into a list, and then change the element, and then

10:50.170 --> 10:52.690
finally convert back again to the tuple if you want.

10:52.720 --> 10:55.210
Okay, that is how you can actually do okay.

10:55.240 --> 10:58.570
But by default you'll be seeing that tuples are immutable.

10:58.570 --> 10:59.230
Perfect.

10:59.230 --> 11:00.790
So till here we have understood.

11:00.820 --> 11:04.090
Now let's go ahead and discuss about tuple methods.

11:04.120 --> 11:04.690
Okay.

11:04.690 --> 11:06.400
And now in this tuple method.

11:06.400 --> 11:10.270
So we will be seeing uh two important methods in tuple.

11:10.270 --> 11:12.520
So let's go ahead and uh see this.

11:12.520 --> 11:14.830
So let's say this is my tuple number.

11:15.310 --> 11:22.030
Uh so one of the one of the example that I would like to show you, or one of the method that is commonly

11:22.030 --> 11:23.140
used with tuple.

11:23.140 --> 11:26.110
And there are only two methods that we specifically use okay.

11:26.140 --> 11:28.840
Numbers dot count okay.

11:28.870 --> 11:33.310
Let's say I want to count how many number of times one is present okay.

11:33.310 --> 11:34.930
So let me just go ahead and see this.

11:34.930 --> 11:36.490
And it is only present one time.

11:36.490 --> 11:39.100
Let me just go ahead and make a code over here.

11:39.100 --> 11:40.870
And let me just display the numbers.

11:40.870 --> 11:42.850
I have 123456 okay.

11:42.850 --> 11:49.320
So this count function is like it will just try to count how many number of times the element.

11:49.350 --> 11:52.800
The element that I have given over here is present in this specific tuple.

11:53.190 --> 11:58.770
The next thing is that I will go ahead and print our numbers dot.

11:58.800 --> 12:02.460
Let me just go and do one function which is called as index.

12:02.490 --> 12:05.700
Now let's say I want to understand what is the element present in the index.

12:05.700 --> 12:06.510
Third right.

12:06.540 --> 12:11.520
And if I go ahead and execute here you can see that in the third index 0123.

12:11.550 --> 12:11.970
Right.

12:12.000 --> 12:14.460
Or sorry what is the element.

12:14.460 --> 12:14.880
Like.

12:14.910 --> 12:17.130
What where is this third element present.

12:17.130 --> 12:20.070
Like in which index this third element is present right.

12:20.100 --> 12:21.540
Or this three is present.

12:21.840 --> 12:23.100
Uh, again let me repeat it.

12:23.100 --> 12:25.350
Um numbers dot index.

12:25.350 --> 12:26.940
Index is a function over here.

12:26.940 --> 12:32.820
And with respect to index what it does is that it returns the first index of the value.

12:32.850 --> 12:33.210
Okay.

12:33.240 --> 12:37.320
Whatever value I'm actually giving you, it is just going to return the index of that value.

12:37.320 --> 12:39.240
So here you can see 012.

12:39.270 --> 12:42.030
So three is basically present in the second index.

12:42.060 --> 12:42.540
Okay.

12:42.540 --> 12:48.060
So I hope you have got this two methods easily and you have understood it.

12:48.090 --> 12:49.920
One is count and one is index.

12:49.920 --> 12:53.880
And these are the two common methods that are specifically used with tuples.

12:53.910 --> 12:54.450
Okay.

12:54.480 --> 12:58.950
Now let me talk about one amazing thing okay.

12:58.980 --> 13:04.200
And that is basically called as packing and unpacking tuple okay.

13:04.230 --> 13:06.930
Packing and unpacking tuple.

13:06.930 --> 13:12.510
Again this will be really handy whenever you are developing projects whenever you are writing code.

13:12.540 --> 13:12.870
Right.

13:12.870 --> 13:17.700
So let me just go ahead and write packed underscore tuple is equal to and I will define the elements

13:17.700 --> 13:19.710
like this one comma.

13:19.710 --> 13:21.390
And let's say this is my string.

13:21.390 --> 13:23.310
So this will be like hello.

13:23.340 --> 13:26.400
Then I have 3.14 okay.

13:26.400 --> 13:31.590
And I will just go ahead and print my packed underscore tuple.

13:31.620 --> 13:34.950
Now once I do this here you'll be able to see that I'm able to get it.

13:34.980 --> 13:39.630
Now whenever I define the numbers in this way like comma separated right.

13:39.660 --> 13:43.740
By default, what it is going to do is that whatever number of elements that I have given, it is going

13:43.740 --> 13:46.000
to pack them in a tuple itself, right?

13:46.000 --> 13:49.990
So that is the reason we say it as we are packing a tuple whenever we give this.

13:50.350 --> 13:53.140
Now how do we unpack a tuple.

13:53.140 --> 13:54.970
So this is with respect to packing.

13:55.030 --> 13:57.010
Okay packing.

13:57.010 --> 13:58.720
But how do we unpack it.

13:58.720 --> 14:02.650
So unpacking a tuple and how do we do it.

14:02.650 --> 14:06.220
So here we know that there are three elements inside this tuple.

14:06.220 --> 14:08.380
Let's say I have four elements of five elements.

14:08.620 --> 14:10.660
Let's say in this case there are three elements.

14:10.660 --> 14:12.700
So I am just going to create three variable.

14:12.700 --> 14:14.740
Let's say ABC is equal to.

14:14.740 --> 14:19.870
And here what I'm actually going to do I'm going to use the same pack tuple okay.

14:19.900 --> 14:24.940
Now what will happen if I go ahead and print a okay.

14:24.970 --> 14:27.400
And let me just go ahead and print B.

14:27.730 --> 14:31.120
And similarly let me just go ahead and print C.

14:31.150 --> 14:33.100
So here you can see one hello.

14:33.100 --> 14:34.900
And 3.14 right.

14:34.900 --> 14:36.400
So you are able to see this.

14:36.400 --> 14:41.110
And this is nothing but it is called as unpacking a tuple right now.

14:41.110 --> 14:46.730
Uh there is also some very important things that you really need to understand.

14:46.760 --> 14:47.300
Okay.

14:47.600 --> 14:51.290
Uh, with respect to unpacking, we can also use star.

14:51.410 --> 14:51.920
Okay.

14:51.950 --> 14:54.920
So let's say unpacking with star.

14:54.950 --> 14:55.160
Okay.

14:55.190 --> 14:59.780
And this is something new that you will be able to see as new new Python version will be coming.

14:59.810 --> 15:01.250
Some of the amazing features.

15:01.250 --> 15:03.470
So let's say I have a numbers.

15:03.590 --> 15:08.180
And inside these numbers I define a tuple 12345 okay.

15:08.210 --> 15:09.560
And six okay.

15:09.650 --> 15:11.750
Now let me do one thing.

15:11.750 --> 15:14.330
I will create one variable like this.

15:14.330 --> 15:15.890
And I'll use star.

15:16.160 --> 15:20.180
Let's say star will be middle and my third variable will be last.

15:20.210 --> 15:20.810
Okay.

15:21.200 --> 15:24.080
Now why I'm creating this you'll be able to understand.

15:24.110 --> 15:25.940
Now see if I go ahead and display the number.

15:25.970 --> 15:28.430
Or I'm just going to assign this particular numbers over here.

15:28.460 --> 15:31.400
Now let me just go ahead and print first.

15:31.760 --> 15:36.110
Then I will go ahead and print middle.

15:36.320 --> 15:36.950
Okay.

15:36.980 --> 15:40.490
Sorry I'll remove the star over here I'll not require star.

15:40.490 --> 15:43.710
And then finally I will print the last element.

15:44.190 --> 15:46.290
Okay, now see what will happen.

15:46.710 --> 15:47.370
Over here.

15:47.370 --> 15:52.290
I know six elements are there, but I'm just using three variables just to unpack.

15:52.290 --> 15:55.800
And I'm unpacking with one star I'm using in the middle variable.

15:55.800 --> 15:56.340
One star.

15:56.370 --> 15:56.550
Okay.

15:56.580 --> 15:58.170
Now see what will be the output.

15:58.200 --> 15:58.650
Okay.

15:58.650 --> 16:00.660
So the first one has given me one.

16:00.660 --> 16:01.440
This is fine.

16:01.470 --> 16:02.610
Now the middle star.

16:02.640 --> 16:03.780
What it has done right.

16:03.780 --> 16:04.800
The star middle.

16:04.800 --> 16:07.860
It has taken all the remaining elements till the last element.

16:07.890 --> 16:09.270
See two, three, four, five.

16:09.270 --> 16:12.090
And the last number is basically giving you the sixth.

16:12.120 --> 16:12.600
Right.

16:12.600 --> 16:19.440
So what the star does is that from wherever you are probably starting right till the last element,

16:19.470 --> 16:22.170
right before that last element, all the elements will be picked up.

16:22.200 --> 16:22.710
Okay.

16:22.740 --> 16:24.750
So this was about unpacking.

16:24.750 --> 16:29.730
Three variants have actually shown you packing unpacking a tuple and unpacking with a star.

16:29.760 --> 16:30.330
Okay.

16:30.660 --> 16:36.750
Uh, let me just go ahead and create more cells so that you'll be able to, uh, will be able to execute

16:36.750 --> 16:37.350
more code.

16:37.380 --> 16:37.890
Okay.

16:37.920 --> 16:43.030
Now let's go ahead and see some example for next tuples.

16:43.060 --> 16:43.600
Okay.

16:44.230 --> 16:47.440
Tuples inside a tuple is basically called as nested tuples.

16:47.440 --> 16:50.290
List inside a list is also called as nested list.

16:50.290 --> 16:56.380
So let's say if I go ahead and write like this, uh, I can go ahead and create any number of list inside

16:56.380 --> 16:57.040
a list.

16:57.070 --> 16:57.640
Okay.

16:57.730 --> 17:00.280
Let's say I have elements like one, two, three, four.

17:00.730 --> 17:04.660
Here I have six comma seven eight, nine.

17:04.660 --> 17:08.890
And let's say I have one comma, one comma.

17:08.920 --> 17:11.140
Hello comma.

17:11.920 --> 17:15.850
Uh, hello comma 3.14 comma.

17:16.390 --> 17:19.360
Uh, see.

17:19.390 --> 17:19.930
Okay.

17:19.960 --> 17:23.020
Now this is what this is list inside a list.

17:23.050 --> 17:23.560
Right.

17:23.560 --> 17:27.790
So here is an example of nested list okay.

17:27.820 --> 17:31.330
Because see I do not take in the previous session of list.

17:31.360 --> 17:34.660
The reason is only that whenever is the right opportunity right.

17:34.660 --> 17:36.310
We should include this topic over there.

17:36.340 --> 17:36.730
Right.

17:36.730 --> 17:40.220
And that is how you will be able to understand all the other topics itself, right?

17:40.220 --> 17:47.090
Because whatever operations we specifically do enlist similarly, only we also do it in tuple also with

17:47.090 --> 17:48.500
respect to accessing the elements.

17:48.500 --> 17:50.900
And the difference is immutability and mutability.

17:50.930 --> 17:54.590
Right now let me just go ahead and write list of zero.

17:55.160 --> 17:58.580
Now list of zero basically means what this is my zeroth index.

17:58.580 --> 17:59.900
This is my first index.

17:59.900 --> 18:01.460
This is my second index okay.

18:01.460 --> 18:06.920
So if I'm writing list of zero you will be able to see that I'm able to get one, two three, four.

18:06.920 --> 18:11.240
But let's say that I want to pick up third element now to pick up third element.

18:11.240 --> 18:13.670
What I really need to do I have to use another index.

18:13.670 --> 18:17.150
And this time this will be nothing but 012.

18:17.180 --> 18:19.550
So this will basically belong to my second index.

18:19.580 --> 18:19.790
Right.

18:19.820 --> 18:23.210
So here you can probably see that I'm able to get the third element right.

18:23.210 --> 18:26.360
So this is some common example right.

18:26.360 --> 18:32.270
Let's say I want to also use slicing operation I want to get the elements between one till four okay.

18:32.300 --> 18:38.460
So I can also go ahead and write like this zero colon sorry zero colon three Okay.

18:38.490 --> 18:39.480
If I go ahead and write it.

18:39.480 --> 18:41.070
So see I'm able to get one, two, three.

18:41.070 --> 18:45.150
So slicing operation can also be applied in nested list okay.

18:45.180 --> 18:47.100
List within a list okay.

18:47.460 --> 18:49.860
Now and it is not like only you need to have a list.

18:49.890 --> 18:51.300
You can also have tuples.

18:51.300 --> 18:52.950
You can also have multiple things right.

18:52.950 --> 18:57.270
So let's say I am going to probably go ahead and define this as tuple okay.

18:57.750 --> 18:59.280
Tuple okay.

18:59.490 --> 19:06.060
Or let me just show you in another example so that this code remains and I'll paste it over here okay.

19:06.090 --> 19:07.530
And let me do one thing.

19:07.980 --> 19:09.750
And here you have this.

19:10.380 --> 19:12.300
And here you have this okay.

19:12.330 --> 19:18.480
Now if I'm executing this let's say I want to probably get from my second index 012 okay.

19:18.510 --> 19:19.320
Second index.

19:19.320 --> 19:22.020
And let's say I want all the elements between zero to third index.

19:22.020 --> 19:24.930
So here I'll be able to get one hello world and 3.14.

19:24.930 --> 19:27.420
So inside a list also you can have tuples okay.

19:27.450 --> 19:29.670
It is up to you however you want to create.

19:29.670 --> 19:34.080
But whenever we talk about nested tuples let me just give you one basic example.

19:34.080 --> 19:34.560
Here.

19:34.560 --> 19:36.810
We are just going to create tuples inside a tuple.

19:36.810 --> 19:37.960
So I have 123.

19:37.990 --> 19:39.700
A b c true false okay.

19:39.730 --> 19:41.620
So these are my tuples over here.

19:41.650 --> 19:44.470
Now we will try to access the elements.

19:45.310 --> 19:47.590
Access the elements.

19:48.370 --> 19:53.530
Access the elements inside a tuple okay.

19:53.560 --> 19:56.140
Now let me just go ahead and write print.

19:57.160 --> 20:00.490
Nested underscore tuple of zero.

20:00.520 --> 20:02.560
So if I go ahead and execute it I'm able to get.

20:02.590 --> 20:03.760
123 okay.

20:03.790 --> 20:07.030
If I want to just pick up C let's let's consider that I want to just go.

20:07.060 --> 20:07.870
Ahead and pick up C.

20:07.900 --> 20:08.920
Then how do I write.

20:08.950 --> 20:13.120
I will go ahead and write print nested underscore.

20:13.150 --> 20:14.020
Tuple.

20:14.800 --> 20:19.060
And here I'm going to specifically write a zeroth first index.

20:19.090 --> 20:19.330
Right.

20:19.360 --> 20:20.050
First index will.

20:20.080 --> 20:21.970
Basically give me all the elements over here.

20:21.970 --> 20:23.920
And this will be my second index right.

20:23.950 --> 20:27.880
So here if I go ahead and execute it I'm able to get C right.

20:28.240 --> 20:31.030
I can also iterate through this nested.

20:31.060 --> 20:32.980
Tuples right by using a for loop.

20:32.980 --> 20:40.280
So iterating Iterating over nested tuples.

20:40.310 --> 20:40.940
Okay.

20:41.120 --> 20:49.250
And here you'll be able to see for sub underscore tuple in nested underscore tuple.

20:49.280 --> 20:50.030
Okay.

20:50.060 --> 20:52.100
I'll first of all go to the nested tuple.

20:52.100 --> 20:57.620
And then I will take the item item in the sub tuple.

20:58.070 --> 21:00.080
And let me just go ahead and print it.

21:00.110 --> 21:01.760
Let's print the item one by one.

21:01.790 --> 21:02.330
Right.

21:02.360 --> 21:03.740
So print item.

21:03.740 --> 21:08.270
And here I'm just going to write end is equal to with a blank statement.

21:08.270 --> 21:14.780
So that whenever it is printing it should print um along with this blank a new line also.

21:14.810 --> 21:19.070
Now if I go ahead and execute see first tuple is basically getting printed one, two, three a, b,

21:19.070 --> 21:20.480
c and then true and false.

21:20.480 --> 21:22.340
So that is what I have right.

21:22.370 --> 21:28.610
So this was example with respect to uh tuples we have seen different different operations.

21:28.610 --> 21:30.770
We have seen about packing unpacking.

21:31.010 --> 21:32.690
Uh we have seen the inbuilt methods.

21:32.690 --> 21:35.160
We have seen why do we get an error?

21:35.190 --> 21:36.000
What is immutable?

21:36.030 --> 21:37.020
Immutability.

21:37.320 --> 21:41.970
Everything we have actually seen, and we have also seen some of the examples with respect to our list.

21:42.000 --> 21:42.600
Right.

21:42.630 --> 21:45.660
But overall if you probably see right.

21:45.690 --> 21:48.990
Tuples are a kind of data structure.

21:48.990 --> 21:55.020
Again it will be specifically used when you do some kind of data analysis and all or some or the other

21:55.020 --> 21:55.230
way.

21:55.230 --> 21:59.700
Whenever you are writing the code and all, you will be using this tuple extensively.

21:59.730 --> 22:01.080
Now let me do one thing.

22:01.080 --> 22:06.630
Let me go ahead and finally write the conclusion so that you have this conclusion in mind where all

22:06.630 --> 22:12.480
tuples are tuples are versatile and very useful in various in many real world scenarios where an immutable

22:12.480 --> 22:14.250
and ordered collection of items is required.

22:14.280 --> 22:19.080
They are commonly used in data structure, function, arguments, and return values as dictionary keys.

22:19.080 --> 22:23.670
Understanding how to leverage tuples effectively can improve the efficiency and readability of your

22:23.670 --> 22:24.240
Python code.

22:24.630 --> 22:26.580
So I hope you like this particular video.

22:26.610 --> 22:28.050
This was it for my side.

22:28.050 --> 22:31.710
I will see you all in the next video, where we will be learning about the next data structure that

22:31.710 --> 22:32.940
is called as sets.

22:33.030 --> 22:33.660
Thank you.

22:33.690 --> 22:34.140
Take care.

22:34.140 --> 22:34.530
Bye bye.
