1
00:00:00,000 --> 00:00:00,000
Hello guys.

2
00:00:00,000 --> 00:00:03,000
So we are going to continue the discussion with respect to Python.

3
00:00:03,000 --> 00:00:07,000
And in this video we are going to discuss about our next data structure, which is called as tuples.

4
00:00:07,000 --> 00:00:13,000
Already in our previous video we have seen about list and we had written a lot of code.

5
00:00:13,000 --> 00:00:18,000
You know, if you probably I go ahead and show you we had written somewhere around 54 lines of code.

6
00:00:18,000 --> 00:00:20,000
We understood about list comprehension.

7
00:00:20,000 --> 00:00:23,000
We saw different different methods, operations and many more things.

8
00:00:23,000 --> 00:00:27,000
Now, uh, in this session, what all things we are going to discuss.

9
00:00:27,000 --> 00:00:31,000
So I have actually given you the brief outline of the video.

10
00:00:31,000 --> 00:00:35,000
First of all, we are going to understand about tuples, how to create tuples, accessing tuple elements,

11
00:00:35,000 --> 00:00:37,000
tuple operation.

12
00:00:37,000 --> 00:00:40,000
What is this immutable nature of tuples.

13
00:00:40,000 --> 00:00:44,000
And what are some of the, uh tuples common tuple methods that are used.

14
00:00:44,000 --> 00:00:48,000
How to pack and unpack tuples, nested tuples and all these things.

15
00:00:48,000 --> 00:00:51,000
We are going to see with a lot of practical example.

16
00:00:51,000 --> 00:00:57,000
Now before I go ahead, first of all, let me just give you a small definition about tuples.

17
00:00:57,000 --> 00:00:57,000
Right.

18
00:00:57,000 --> 00:01:02,000
So tuples are ordered collection of items that are immutable.

19
00:01:02,000 --> 00:01:02,000
Right.

20
00:01:02,000 --> 00:01:06,000
So we'll understand about this particular meaning which is called as immutable.

21
00:01:06,000 --> 00:01:09,000
If I talk about list it is an ordered collection of items.

22
00:01:09,000 --> 00:01:11,000
And the items can be of any type.

23
00:01:11,000 --> 00:01:13,000
And they are mutable right.

24
00:01:13,000 --> 00:01:16,000
But here it is something like immutable.

25
00:01:16,000 --> 00:01:18,000
They are similar to list, but they are immutable.

26
00:01:18,000 --> 00:01:20,000
Their immutability makes them different.

27
00:01:20,000 --> 00:01:25,000
Now first of all, we'll try to understand how to go ahead and create a tuple.

28
00:01:25,000 --> 00:01:32,000
So for creating a tuple right we have to just use this two empty brackets.

29
00:01:32,000 --> 00:01:34,000
So let me just go ahead and write it over here.

30
00:01:34,000 --> 00:01:36,000
So this is my empty tuple okay.

31
00:01:36,000 --> 00:01:41,000
And just by using this two brackets right I will be able to create it.

32
00:01:41,000 --> 00:01:41,000
Right.

33
00:01:41,000 --> 00:01:48,000
And if I go ahead and display the print, uh, let me first of all print this empty tuple.

34
00:01:48,000 --> 00:01:53,000
And then we will also go ahead and display our type of this particular empty tuple.

35
00:01:54,000 --> 00:01:54,000
Okay.

36
00:01:54,000 --> 00:01:56,000
So here you have this.

37
00:01:56,000 --> 00:02:01,000
If I execute this you can see this is an empty tuple that is getting created in list.

38
00:02:01,000 --> 00:02:02,000
We use two square brackets.

39
00:02:02,000 --> 00:02:05,000
In this we are just using this rounded brackets Right.

40
00:02:05,000 --> 00:02:09,000
And then over here you can see that I'm getting an empty tuple which is completely empty.

41
00:02:09,000 --> 00:02:14,000
And if I go ahead and see the type of empty tuple, it is nothing but tuple itself, right?

42
00:02:14,000 --> 00:02:17,000
Now if I probably consider list right.

43
00:02:17,000 --> 00:02:19,000
So list if I also use like this.

44
00:02:19,000 --> 00:02:20,000
Right.

45
00:02:20,000 --> 00:02:22,000
And if I go ahead and create an empty list.

46
00:02:22,000 --> 00:02:25,000
So I can also use this class directly and create an empty list.

47
00:02:25,000 --> 00:02:28,000
Okay, so this I missed in my previous video.

48
00:02:28,000 --> 00:02:30,000
So I'm just going to show it over here.

49
00:02:30,000 --> 00:02:36,000
And similarly if I want to probably create a tuple let's say this is my tuple, I can actually go ahead

50
00:02:36,000 --> 00:02:40,000
and use the same type of class and create an empty tuple.

51
00:02:40,000 --> 00:02:45,000
So both the ways I'm actually trying to show you so that you understand both these ways.

52
00:02:45,000 --> 00:02:45,000
Right.

53
00:02:45,000 --> 00:02:50,000
So here you can see when I'm seeing the type of this, this will be an list and this will be tuple.

54
00:02:50,000 --> 00:02:51,000
Right.

55
00:02:51,000 --> 00:02:57,000
So you can also use this um uh method in order to create an empty list or tuples.

56
00:02:57,000 --> 00:02:58,000
Okay.

57
00:02:58,000 --> 00:03:00,000
Inside this also I can put up elements.

58
00:03:00,000 --> 00:03:01,000
It is up to us right now.

59
00:03:01,000 --> 00:03:06,000
Let me go ahead and add some elements into this particular tuple okay.

60
00:03:06,000 --> 00:03:09,000
Now how do I add this particular elements.

61
00:03:09,000 --> 00:03:11,000
Uh uh inside this particular tuple.

62
00:03:11,000 --> 00:03:12,000
And uh how to do that.

63
00:03:12,000 --> 00:03:13,000
We'll be seeing a lot of methods.

64
00:03:13,000 --> 00:03:17,000
But here what I'm actually going to do, let me just go ahead and directly create a tuple.

65
00:03:17,000 --> 00:03:21,000
And if I go ahead and write tuple okay.

66
00:03:21,000 --> 00:03:25,000
And here I can actually give a list like 123456 okay.

67
00:03:25,000 --> 00:03:28,000
And now this list will get basically get converted into a tuple.

68
00:03:28,000 --> 00:03:34,000
So if I go ahead and display this numbers here, you can see that I'm actually getting a tuple right.

69
00:03:34,000 --> 00:03:37,000
So that basically means a list can be converted into a tuple.

70
00:03:37,000 --> 00:03:40,000
And even a tuple can be converted in a list.

71
00:03:40,000 --> 00:03:40,000
Right.

72
00:03:40,000 --> 00:03:45,000
So if I go ahead and basically write like this 123456.

73
00:03:45,000 --> 00:03:45,000
Right.

74
00:03:45,000 --> 00:03:48,000
So this is my uh tuple itself.

75
00:03:48,000 --> 00:03:51,000
And now if I go ahead and write list and I close this particular bracket.

76
00:03:51,000 --> 00:03:54,000
So here you'll be able to see that I am able to get a list right.

77
00:03:54,000 --> 00:03:55,000
List of elements.

78
00:03:55,000 --> 00:03:59,000
So both of the ways uh, you can basically do the type conversion okay.

79
00:03:59,000 --> 00:04:05,000
Now as I said, uh, in tuples also you can let's say I'm going to probably go ahead and create my mixed

80
00:04:05,000 --> 00:04:06,000
tuple here.

81
00:04:06,000 --> 00:04:09,000
Also you can use different different data type elements.

82
00:04:09,000 --> 00:04:13,000
Let's say I want to use numerical I want to probably use string.

83
00:04:13,000 --> 00:04:16,000
I want to go ahead and use a floating point number.

84
00:04:16,000 --> 00:04:19,000
I can also go ahead and use my boolean variable.

85
00:04:19,000 --> 00:04:19,000
Right.

86
00:04:19,000 --> 00:04:24,000
So now if I go ahead and print this then also this will get uh created.

87
00:04:24,000 --> 00:04:26,000
The tuple will basically get created.

88
00:04:26,000 --> 00:04:27,000
Okay.

89
00:04:27,000 --> 00:04:32,000
Now this is uh a basic information about tuple, how you can actually create and how you can proceed.

90
00:04:32,000 --> 00:04:33,000
Okay.

91
00:04:33,000 --> 00:04:35,000
Now let me do one thing quickly.

92
00:04:35,000 --> 00:04:40,000
Let me go ahead and explain you about the next thing that we are going to discuss.

93
00:04:40,000 --> 00:04:42,000
It is nothing but accessing tuple elements.

94
00:04:42,000 --> 00:04:43,000
Okay.

95
00:04:43,000 --> 00:04:45,000
Now for accessing tuple elements.

96
00:04:45,000 --> 00:04:48,000
What all things we really need to do that we will be discussing.

97
00:04:48,000 --> 00:04:48,000
Okay.

98
00:04:48,000 --> 00:04:50,000
Like I want to pick up any elements as such.

99
00:04:50,000 --> 00:04:52,000
So right now let me just go ahead and see.

100
00:04:52,000 --> 00:04:53,000
This is my numbers.

101
00:04:53,000 --> 00:04:55,000
Now here you can see that this is in the form of tuples.

102
00:04:55,000 --> 00:04:56,000
I have six elements.

103
00:04:56,000 --> 00:05:00,000
Let's say I go ahead and write numbers of zero okay.

104
00:05:00,000 --> 00:05:04,000
Or let me just go ahead and write it in the land line next line.

105
00:05:04,000 --> 00:05:06,000
So if I go ahead and write numbers of zero.

106
00:05:06,000 --> 00:05:09,000
So here I'll be able to see first element over here.

107
00:05:09,000 --> 00:05:10,000
This is my first zeroth index.

108
00:05:10,000 --> 00:05:12,000
I'm able to see it over here.

109
00:05:12,000 --> 00:05:14,000
Then I have two over here also.

110
00:05:14,000 --> 00:05:16,000
You can see I'm able to pick up this elements right.

111
00:05:16,000 --> 00:05:22,000
Similarly if I go ahead and let's say that I'm just going to print this okay I want to pick up the last

112
00:05:22,000 --> 00:05:23,000
element okay.

113
00:05:23,000 --> 00:05:25,000
Last element.

114
00:05:25,000 --> 00:05:29,000
Either you can directly write the index or what I'm actually going to do, I'm just going to use minus

115
00:05:29,000 --> 00:05:30,000
one.

116
00:05:30,000 --> 00:05:30,000
Right.

117
00:05:30,000 --> 00:05:33,000
So I'll be able to get the last elements again.

118
00:05:33,000 --> 00:05:36,000
Uh the indexing will be almost similar like a list.

119
00:05:36,000 --> 00:05:39,000
Even the slicing operation will be also similar, like a list.

120
00:05:39,000 --> 00:05:39,000
Okay.

121
00:05:39,000 --> 00:05:46,000
So let's say, uh, I go ahead and write numbers and here I'll write zero colon four.

122
00:05:46,000 --> 00:05:50,000
That basically means I'll be able to get the element between zero index to the third index.

123
00:05:50,000 --> 00:05:52,000
So same slicing operation whatever things we have actually discussed.

124
00:05:52,000 --> 00:05:58,000
Similarly, if I go ahead and write numbers with double colon right I'll be able to see it.

125
00:05:58,000 --> 00:06:03,000
If I go ahead and write double colon minus one, I'll be able to get the reverse of all the tuple values

126
00:06:03,000 --> 00:06:05,000
right, but the return type will be always tuple.

127
00:06:05,000 --> 00:06:11,000
Okay, so all the indexing and slicing operation that we have actually done with the help of list.

128
00:06:12,000 --> 00:06:14,000
Similarly, you can actually do it with the help of tuples.

129
00:06:14,000 --> 00:06:21,000
Okay then let's go ahead and see tuples operation tuple operations.

130
00:06:21,000 --> 00:06:22,000
Okay.

131
00:06:22,000 --> 00:06:28,000
Now tuple supports various operations like concatenation repetition and slicing okay.

132
00:06:28,000 --> 00:06:30,000
So we'll be discussing about that.

133
00:06:30,000 --> 00:06:33,000
Let's say I have numbers one tuple okay.

134
00:06:33,000 --> 00:06:38,000
And I had also created another tuple which is called as mixed tuple.

135
00:06:38,000 --> 00:06:38,000
Right.

136
00:06:38,000 --> 00:06:41,000
So this were the elements right.

137
00:06:41,000 --> 00:06:45,000
Now what if I just go ahead and write something like this.

138
00:06:45,000 --> 00:06:47,000
Numbers plus mixed tuple okay.

139
00:06:47,000 --> 00:06:51,000
So here in short this is an arithmetic operation.

140
00:06:51,000 --> 00:06:56,000
But since we have two tuples over here I will definitely say this as a concatenation, right?

141
00:06:56,000 --> 00:06:59,000
Concatenation basically means combining two things, right?

142
00:06:59,000 --> 00:07:04,000
So here you'll be able to see I will just go ahead and write concatenation underscore tuple.

143
00:07:04,000 --> 00:07:06,000
And I will just go ahead and concatenate this.

144
00:07:06,000 --> 00:07:14,000
Now if I go ahead and print this concatenation right concatenation tuple, you'll be able to see that

145
00:07:14,000 --> 00:07:15,000
I will be getting something like this.

146
00:07:15,000 --> 00:07:19,000
Now all this tuple both the elements of this particular tuples has been combined.

147
00:07:19,000 --> 00:07:23,000
So I have 1234, five six then one hello world 3.14 and true.

148
00:07:23,000 --> 00:07:27,000
Okay, now uh, let's say that I want to perform some more operations, right?

149
00:07:27,000 --> 00:07:31,000
Let's say I want to go ahead and write something like this, okay.

150
00:07:31,000 --> 00:07:34,000
Or repeated or let me do one thing.

151
00:07:34,000 --> 00:07:36,000
Let me just go ahead and create this.

152
00:07:37,000 --> 00:07:41,000
So I will just go ahead and do okay.

153
00:07:41,000 --> 00:07:43,000
Or I'll take this mixed tuple.

154
00:07:44,000 --> 00:07:44,000
Okay.

155
00:07:44,000 --> 00:07:47,000
And I will just try to multiply with an operation three.

156
00:07:47,000 --> 00:07:49,000
Now see what will happen.

157
00:07:49,000 --> 00:07:52,000
So here you can see mixed tuple had one.

158
00:07:52,000 --> 00:07:53,000
Hello world 3.14 and true.

159
00:07:53,000 --> 00:07:57,000
Now this has got entirely repeated three times right.

160
00:07:57,000 --> 00:08:02,000
So in this kind of multiplication operation what is basically happening is that the entire tuple is

161
00:08:02,000 --> 00:08:04,000
basically getting appended three times.

162
00:08:04,000 --> 00:08:04,000
Right.

163
00:08:05,000 --> 00:08:08,000
So that that is the reason we are basically doing an operation over here.

164
00:08:08,000 --> 00:08:14,000
So, uh, so this is what is something different with respect to the calculation that we do.

165
00:08:14,000 --> 00:08:18,000
Now you may be thinking, Krish, what about if I try to do this with numbers right.

166
00:08:18,000 --> 00:08:20,000
Numbers multiplied by three.

167
00:08:20,000 --> 00:08:22,000
So here also the same thing will happen.

168
00:08:22,000 --> 00:08:24,000
So 123456123456.

169
00:08:24,000 --> 00:08:25,000
And 123456.

170
00:08:25,000 --> 00:08:31,000
You may be thinking, Krish, wasn't it like you have to probably multiply all these numbers that also

171
00:08:31,000 --> 00:08:35,000
we can do it, but we have to iterate it inside this particular tuple, get each element and then perform

172
00:08:35,000 --> 00:08:36,000
numerical operation.

173
00:08:36,000 --> 00:08:37,000
Okay.

174
00:08:37,000 --> 00:08:42,000
But right now with respect to generic concatenation and this kind of operation here you can see that

175
00:08:42,000 --> 00:08:47,000
three times n number of times based on this multiplication that we are doing that many number of times

176
00:08:47,000 --> 00:08:51,000
this tuple will get element are appended with respect to the element.

177
00:08:51,000 --> 00:08:51,000
Okay.

178
00:08:52,000 --> 00:08:54,000
So these are some of the basic operations.

179
00:08:54,000 --> 00:09:00,000
Now let's go ahead and discuss about immutable nature of tuples.

180
00:09:00,000 --> 00:09:00,000
Okay.

181
00:09:00,000 --> 00:09:03,000
This is important of tuples.

182
00:09:04,000 --> 00:09:09,000
Now in the immutable immutable nature of tuples you need to understand one thing.

183
00:09:09,000 --> 00:09:13,000
And that is the first point that we have already learned right.

184
00:09:13,000 --> 00:09:15,000
Tuples are immutable.

185
00:09:15,000 --> 00:09:16,000
Okay.

186
00:09:16,000 --> 00:09:19,000
Meaning the elements cannot be changed once assigned.

187
00:09:19,000 --> 00:09:23,000
Okay, let's say that I go ahead and create my list and I go ahead and write one, two, three, four,

188
00:09:23,000 --> 00:09:24,000
five.

189
00:09:24,000 --> 00:09:24,000
Right.

190
00:09:24,000 --> 00:09:26,000
Now let me do one thing.

191
00:09:26,000 --> 00:09:27,000
List of zero.

192
00:09:28,000 --> 00:09:34,000
Or if I go ahead and print this specific list, uh, I will be okay.

193
00:09:34,000 --> 00:09:35,000
There is an error.

194
00:09:35,000 --> 00:09:36,000
Don't worry.

195
00:09:36,000 --> 00:09:39,000
Okay, so here you can see I'll be getting this specific element.

196
00:09:39,000 --> 00:09:41,000
Now let's see this okay.

197
00:09:41,000 --> 00:09:46,000
Now what I will do I will go ahead and take the first index and replace with it.

198
00:09:46,000 --> 00:09:47,000
Crush okay.

199
00:09:48,000 --> 00:09:49,000
Now I'll go ahead and print the list.

200
00:09:49,000 --> 00:09:51,000
Now see what will happen.

201
00:09:51,000 --> 00:09:53,000
So here we are changing the element.

202
00:09:53,000 --> 00:09:58,000
And this second index or this first index element has got replaced with crush.

203
00:09:58,000 --> 00:10:01,000
So this basically means uh list are mutable.

204
00:10:01,000 --> 00:10:04,000
That basically means the element can be changed once assigned.

205
00:10:04,000 --> 00:10:10,000
Now similar operation if I try to do with the same numbers that we had, write in the form of tuple.

206
00:10:10,000 --> 00:10:13,000
If I go ahead and say hey, number of one, what is the number of one two?

207
00:10:13,000 --> 00:10:17,000
If I try to assign some value, let's say I try to assign a value called as Krish.

208
00:10:17,000 --> 00:10:22,000
Here it says that hey tuple object does not support item assignment.

209
00:10:22,000 --> 00:10:26,000
And this is what immutable immutability comes into picture.

210
00:10:27,000 --> 00:10:28,000
Tuples are immutable.

211
00:10:28,000 --> 00:10:30,000
The elements cannot be changed once assigned.

212
00:10:30,000 --> 00:10:35,000
Okay So here you can actually see what I exactly mean to say.

213
00:10:35,000 --> 00:10:35,000
Right.

214
00:10:35,000 --> 00:10:37,000
And this is very much important.

215
00:10:37,000 --> 00:10:41,000
That basically means once you have defined a tuple you cannot change the element inside that okay.

216
00:10:41,000 --> 00:10:45,000
Once it is assigned there are ways how you can do it.

217
00:10:45,000 --> 00:10:50,000
First of all, you can take the tuple, convert into a list, and then change the element and then finally

218
00:10:50,000 --> 00:10:52,000
convert back again to the tuple if you want.

219
00:10:52,000 --> 00:10:57,000
Okay, that is how you can actually do okay, But by default, uh, you'll be seeing that tuples are

220
00:10:57,000 --> 00:10:58,000
immutable.

221
00:10:58,000 --> 00:10:59,000
Perfect.

222
00:10:59,000 --> 00:11:00,000
So till here we have understood.

223
00:11:00,000 --> 00:11:04,000
Now let's go ahead and discuss about tuple methods okay.

224
00:11:04,000 --> 00:11:10,000
And now in this tuple methods uh we will be seeing uh two important methods in tuple.

225
00:11:10,000 --> 00:11:12,000
So let's go ahead and uh see this.

226
00:11:12,000 --> 00:11:14,000
So let's say this is my tuple number.

227
00:11:15,000 --> 00:11:22,000
Uh so one of the, one of the example that I would like to show you, or one of the method that is commonly

228
00:11:22,000 --> 00:11:23,000
used with people.

229
00:11:23,000 --> 00:11:25,000
And there are only two methods that we specifically use.

230
00:11:25,000 --> 00:11:26,000
Okay.

231
00:11:26,000 --> 00:11:28,000
Numbers dot count.

232
00:11:28,000 --> 00:11:28,000
Okay.

233
00:11:28,000 --> 00:11:33,000
Let's say I want to count how many number of times one is present okay.

234
00:11:33,000 --> 00:11:34,000
So let me just go ahead and see this.

235
00:11:34,000 --> 00:11:36,000
And it is only present one time.

236
00:11:36,000 --> 00:11:39,000
Let me just go ahead and make a code over here.

237
00:11:39,000 --> 00:11:40,000
And let me just display the numbers.

238
00:11:40,000 --> 00:11:42,000
I have 123456 okay.

239
00:11:42,000 --> 00:11:49,000
So this count function is like it'll just try to count how many number of times the element.

240
00:11:49,000 --> 00:11:52,000
The element that I have given over here is present in the specific tuple.

241
00:11:53,000 --> 00:11:57,000
The next thing is that I will go ahead and print uh numbers.

242
00:11:57,000 --> 00:11:58,000
Dot.

243
00:11:58,000 --> 00:12:02,000
Let me just go ahead and do one function which is called as index.

244
00:12:02,000 --> 00:12:05,000
Now let's say I want to understand what is the element present in the index.

245
00:12:05,000 --> 00:12:06,000
Third.

246
00:12:06,000 --> 00:12:06,000
Right.

247
00:12:06,000 --> 00:12:11,000
And if I go ahead and execute here, you can see that in the third index 0123.

248
00:12:11,000 --> 00:12:12,000
Right.

249
00:12:12,000 --> 00:12:14,000
Or sorry what is the element like.

250
00:12:14,000 --> 00:12:17,000
Uh what uh where is this third element present.

251
00:12:17,000 --> 00:12:19,000
Like in which index this third element is present.

252
00:12:19,000 --> 00:12:20,000
Right.

253
00:12:20,000 --> 00:12:21,000
Or this three is present.

254
00:12:21,000 --> 00:12:23,000
Uh, again let me repeat it.

255
00:12:23,000 --> 00:12:25,000
Um, numbers dot index.

256
00:12:25,000 --> 00:12:26,000
Index is a function over here.

257
00:12:26,000 --> 00:12:33,000
And with respect to index, what it does is that it returns the first index of the value, okay.

258
00:12:33,000 --> 00:12:37,000
Whatever value I'm actually giving you, it is just going to return the index of that value.

259
00:12:37,000 --> 00:12:39,000
So here you can see 012.

260
00:12:39,000 --> 00:12:42,000
So three is basically present in the second index okay.

261
00:12:42,000 --> 00:12:48,000
So I hope you have got this two methods easily and you have understood it.

262
00:12:48,000 --> 00:12:49,000
One is count and one is index.

263
00:12:49,000 --> 00:12:53,000
And these are the two common methods that are specifically used with tuples.

264
00:12:53,000 --> 00:12:54,000
Okay.

265
00:12:54,000 --> 00:12:58,000
Now now let me talk about one amazing thing okay.

266
00:12:58,000 --> 00:13:04,000
And that is basically called as packing and unpacking tuple okay.

267
00:13:04,000 --> 00:13:06,000
Packing and unpacking tuple.

268
00:13:06,000 --> 00:13:12,000
Again this will be really handy whenever you are developing projects, whenever you are writing the

269
00:13:12,000 --> 00:13:12,000
code.

270
00:13:12,000 --> 00:13:12,000
Right.

271
00:13:12,000 --> 00:13:17,000
So let me just go ahead and write packed underscore tuple is equal to and I will define the elements

272
00:13:17,000 --> 00:13:19,000
like this one comma.

273
00:13:19,000 --> 00:13:21,000
And let's say this is my string.

274
00:13:21,000 --> 00:13:23,000
So this will be like hello.

275
00:13:23,000 --> 00:13:26,000
Then I have 3.14 okay.

276
00:13:26,000 --> 00:13:31,000
And I will just go ahead and print my packed underscore tuple.

277
00:13:31,000 --> 00:13:34,000
Now once I do this here you'll be able to see that I'm able to get it.

278
00:13:34,000 --> 00:13:41,000
Now whenever I define the numbers in this way like comma separated right by default, what it is going

279
00:13:41,000 --> 00:13:45,000
to do is that whatever number of elements that I have given, it is going to pack them in a tuple itself,

280
00:13:45,000 --> 00:13:46,000
right?

281
00:13:46,000 --> 00:13:49,000
So that is the reason we say it as we are packing a tuple whenever we give this.

282
00:13:50,000 --> 00:13:53,000
Now how do we unpack a tuple.

283
00:13:53,000 --> 00:13:56,000
So this is with respect to packing okay packing.

284
00:13:56,000 --> 00:13:58,000
But how do we unpack it.

285
00:13:58,000 --> 00:14:02,000
So unpacking a tuple and how do we do it.

286
00:14:02,000 --> 00:14:06,000
So here we know that there are three elements inside this tuple.

287
00:14:06,000 --> 00:14:08,000
Let's say I have four elements of five elements.

288
00:14:08,000 --> 00:14:10,000
Let's say in this case there are three elements.

289
00:14:10,000 --> 00:14:12,000
So I am just going to create three variable.

290
00:14:12,000 --> 00:14:14,000
Let's say a b c is equal to.

291
00:14:14,000 --> 00:14:19,000
And here what I'm actually going to do I'm going to use the same PAC tuple okay.

292
00:14:19,000 --> 00:14:24,000
Now what will happen if I go ahead and print a.

293
00:14:24,000 --> 00:14:24,000
Okay.

294
00:14:24,000 --> 00:14:27,000
And let me just go ahead and print B.

295
00:14:27,000 --> 00:14:31,000
And similarly let me just go ahead and print C.

296
00:14:31,000 --> 00:14:33,000
So here you can see one hello.

297
00:14:33,000 --> 00:14:34,000
And 3.14 right.

298
00:14:34,000 --> 00:14:36,000
So you are able to see this.

299
00:14:36,000 --> 00:14:41,000
And this is nothing but it is called as unpacking a tuple right now.

300
00:14:41,000 --> 00:14:46,000
Uh there is also some very important things, uh, that you really need to understand.

301
00:14:46,000 --> 00:14:47,000
Okay.

302
00:14:47,000 --> 00:14:51,000
Uh, with respect to unpacking, we can also use star.

303
00:14:51,000 --> 00:14:51,000
Okay.

304
00:14:51,000 --> 00:14:55,000
So let's say unpacking with star okay.

305
00:14:55,000 --> 00:14:59,000
And this is something new that you will be able to see as new new Python version will be coming.

306
00:14:59,000 --> 00:15:01,000
Some of the amazing features.

307
00:15:01,000 --> 00:15:07,000
So let's say I have a numbers and in these numbers I define a tuple one, two, three, four, five

308
00:15:07,000 --> 00:15:08,000
okay and six.

309
00:15:08,000 --> 00:15:09,000
Okay.

310
00:15:09,000 --> 00:15:11,000
Now let me do one thing.

311
00:15:11,000 --> 00:15:14,000
I will create one variable like this.

312
00:15:14,000 --> 00:15:15,000
And I'll use star.

313
00:15:16,000 --> 00:15:20,000
Let's say star will be middle and my third variable will be last.

314
00:15:20,000 --> 00:15:24,000
Okay, now why I'm creating this, you'll be able to understand.

315
00:15:24,000 --> 00:15:28,000
Now see if I go ahead and display the number, or I'm just going to assign this particular numbers over

316
00:15:28,000 --> 00:15:28,000
here.

317
00:15:28,000 --> 00:15:31,000
Now let me just go ahead and print first.

318
00:15:31,000 --> 00:15:36,000
Then I will go ahead and print middle okay.

319
00:15:36,000 --> 00:15:40,000
Sorry I'll remove the star over here I'll not require star.

320
00:15:40,000 --> 00:15:46,000
And then finally I will print the last element Okay, now see what will happen.

321
00:15:46,000 --> 00:15:47,000
Over here.

322
00:15:47,000 --> 00:15:52,000
I know six elements are there, but I'm just using three variables just to unpack.

323
00:15:52,000 --> 00:15:55,000
And I'm unpacking with one star I'm using in the middle variable.

324
00:15:55,000 --> 00:15:56,000
One star.

325
00:15:56,000 --> 00:15:56,000
Okay.

326
00:15:56,000 --> 00:15:58,000
Now see what will be the output okay.

327
00:15:58,000 --> 00:16:00,000
So the first one has given me one.

328
00:16:00,000 --> 00:16:01,000
This is fine.

329
00:16:01,000 --> 00:16:03,000
Now the middle star what it has done right.

330
00:16:03,000 --> 00:16:04,000
The star middle.

331
00:16:04,000 --> 00:16:07,000
It has taken all the remaining elements till the last element.

332
00:16:07,000 --> 00:16:09,000
See C23, four, five.

333
00:16:09,000 --> 00:16:12,000
And the last number is basically giving you the sixth.

334
00:16:12,000 --> 00:16:12,000
Right.

335
00:16:12,000 --> 00:16:19,000
So what the star does is that from wherever you are probably starting right till the last element,

336
00:16:19,000 --> 00:16:22,000
right before that last element, all the elements will be picked up.

337
00:16:22,000 --> 00:16:22,000
Okay.

338
00:16:22,000 --> 00:16:24,000
So this was about unpacking.

339
00:16:24,000 --> 00:16:29,000
Three variants have actually shown you packing unpacking a tuple and pack unpacking with a star.

340
00:16:29,000 --> 00:16:30,000
Okay.

341
00:16:30,000 --> 00:16:36,000
Uh, let me just go ahead and create more cells so that you'll be able to, uh, will be able to execute

342
00:16:36,000 --> 00:16:37,000
more code.

343
00:16:37,000 --> 00:16:37,000
Okay.

344
00:16:37,000 --> 00:16:43,000
Now let's go ahead and see some example for next tuples.

345
00:16:43,000 --> 00:16:43,000
Okay.

346
00:16:44,000 --> 00:16:47,000
Tuples inside a tuple is basically called as nested tuples.

347
00:16:47,000 --> 00:16:50,000
List inside a list is also called as nested list.

348
00:16:50,000 --> 00:16:56,000
So let's say if I go ahead and write like this, uh I can go ahead and create any number of list inside

349
00:16:56,000 --> 00:16:57,000
a list.

350
00:16:57,000 --> 00:16:57,000
Okay.

351
00:16:57,000 --> 00:17:00,000
Let's say I have elements like one, two, three, four.

352
00:17:00,000 --> 00:17:04,000
Here I have, um, six comma, seven comma, eight comma nine.

353
00:17:04,000 --> 00:17:08,000
And let's say I have one comma, one comma.

354
00:17:08,000 --> 00:17:11,000
Hello, comma.

355
00:17:11,000 --> 00:17:15,000
Uh, hello, comma 3.14 comma.

356
00:17:16,000 --> 00:17:19,000
Uh, see.

357
00:17:19,000 --> 00:17:19,000
Okay.

358
00:17:19,000 --> 00:17:21,000
Now this is what this is.

359
00:17:21,000 --> 00:17:23,000
List inside a list.

360
00:17:23,000 --> 00:17:23,000
Right.

361
00:17:23,000 --> 00:17:27,000
So here is an example of nested list okay.

362
00:17:27,000 --> 00:17:31,000
Because see I do not take in the previous session of list.

363
00:17:31,000 --> 00:17:34,000
The reason is only that whenever is the right opportunity right.

364
00:17:34,000 --> 00:17:36,000
We should include this topic over there.

365
00:17:36,000 --> 00:17:36,000
Right.

366
00:17:36,000 --> 00:17:39,000
And that is how you'll be able to understand all the other topics itself.

367
00:17:39,000 --> 00:17:40,000
Right?

368
00:17:40,000 --> 00:17:45,000
Because whatever operations we specifically do in list, similarly, only, uh, we also do it uh,

369
00:17:45,000 --> 00:17:48,000
in tuple also with respect to accessing the elements.

370
00:17:48,000 --> 00:17:50,000
And the difference is immutability and mutability.

371
00:17:50,000 --> 00:17:54,000
Right now let me just go ahead and write list of zero.

372
00:17:55,000 --> 00:17:58,000
Now list of zero basically means what this is my zeroth index.

373
00:17:58,000 --> 00:17:59,000
This is my first index.

374
00:17:59,000 --> 00:18:01,000
This is my second index okay.

375
00:18:01,000 --> 00:18:06,000
So if I'm writing list of zero you will be able to see that I am able to get one, two, three, four.

376
00:18:06,000 --> 00:18:09,000
But let's say that I want to pick up third element.

377
00:18:09,000 --> 00:18:13,000
Now to pick up third element, what I really need to do, I have to use another index.

378
00:18:13,000 --> 00:18:17,000
And this time this will be nothing but zero one, two.

379
00:18:17,000 --> 00:18:19,000
So this will basically belong to my second index.

380
00:18:19,000 --> 00:18:19,000
Right.

381
00:18:19,000 --> 00:18:23,000
So here you can probably see that I am able to get the third element right.

382
00:18:23,000 --> 00:18:26,000
So this is some common example right.

383
00:18:26,000 --> 00:18:32,000
Let's say I want to also use slicing operation I want to get the elements between one till four okay.

384
00:18:32,000 --> 00:18:35,000
So I can also go ahead and write like this zero colon.

385
00:18:35,000 --> 00:18:38,000
Sorry zero colon three okay.

386
00:18:38,000 --> 00:18:39,000
If I go ahead and write it.

387
00:18:39,000 --> 00:18:41,000
So see I am able to get 123.

388
00:18:41,000 --> 00:18:45,000
So slicing operation can also be applied in nested list okay.

389
00:18:45,000 --> 00:18:47,000
List within a list okay.

390
00:18:47,000 --> 00:18:49,000
Uh and it is not like only you need to have a list.

391
00:18:49,000 --> 00:18:51,000
You can also have tuples.

392
00:18:51,000 --> 00:18:52,000
You can also have multiple things.

393
00:18:52,000 --> 00:18:52,000
Right.

394
00:18:52,000 --> 00:18:57,000
So let's say I am going to probably go ahead and define this as tuple okay.

395
00:18:57,000 --> 00:18:59,000
Tuple okay.

396
00:18:59,000 --> 00:19:06,000
Or let me just show you in another example so that this code remains and I'll paste it over here okay.

397
00:19:06,000 --> 00:19:07,000
And let me do one thing.

398
00:19:07,000 --> 00:19:09,000
And here you have this.

399
00:19:10,000 --> 00:19:12,000
And here you have this okay.

400
00:19:12,000 --> 00:19:18,000
Now if I'm executing this let's say I want to probably get from my second index 012 okay.

401
00:19:18,000 --> 00:19:19,000
Second index.

402
00:19:19,000 --> 00:19:22,000
And let's say I want all the elements between zero to third index.

403
00:19:22,000 --> 00:19:24,000
So here I'll be able to get one hello world and 3.14.

404
00:19:24,000 --> 00:19:27,000
So inside a list also you can have tuples okay.

405
00:19:27,000 --> 00:19:29,000
It is up to you however you want to create.

406
00:19:29,000 --> 00:19:34,000
But whenever we talk about nested tuples uh let me just give you one basic example.

407
00:19:34,000 --> 00:19:34,000
Here.

408
00:19:34,000 --> 00:19:36,000
We are just going to create tuples inside a tuple.

409
00:19:36,000 --> 00:19:39,000
So I have 123ABC true false okay.

410
00:19:39,000 --> 00:19:41,000
So these are my tuples over here.

411
00:19:41,000 --> 00:19:44,000
Now we will try to access the elements.

412
00:19:45,000 --> 00:19:47,000
Access the elements.

413
00:19:48,000 --> 00:19:52,000
Access the elements inside a tuple.

414
00:19:52,000 --> 00:19:53,000
Okay.

415
00:19:53,000 --> 00:20:00,000
Now let me just go ahead and write print nested underscore tuple of zero.

416
00:20:00,000 --> 00:20:03,000
So if I go ahead and execute it I'm able to get 123 okay.

417
00:20:03,000 --> 00:20:07,000
If I want to just pick up C let's let's consider that I want to just go ahead and pick up C.

418
00:20:07,000 --> 00:20:13,000
Then how do I write I'll go ahead and write print nested underscore tuple.

419
00:20:14,000 --> 00:20:19,000
And here I'm going to specifically write uh zeroth uh first index.

420
00:20:19,000 --> 00:20:19,000
Right.

421
00:20:19,000 --> 00:20:21,000
First index will basically get me all the elements over here.

422
00:20:21,000 --> 00:20:23,000
And this will be my second index.

423
00:20:23,000 --> 00:20:23,000
Right.

424
00:20:23,000 --> 00:20:27,000
So here if I go ahead and execute it I'm able to get C right.

425
00:20:28,000 --> 00:20:32,000
I can also iterate through this nested tuples right by using a for loop.

426
00:20:32,000 --> 00:20:40,000
So iterating iterating over nested tuples.

427
00:20:40,000 --> 00:20:40,000
Okay.

428
00:20:41,000 --> 00:20:49,000
And here you'll be able to see for sub underscore tuple in nested underscore tuple.

429
00:20:49,000 --> 00:20:52,000
Okay I'll first of all go to the nested tuple.

430
00:20:52,000 --> 00:20:57,000
And then I will take the item item in the sub tuple.

431
00:20:58,000 --> 00:21:00,000
And let me just go ahead and print it.

432
00:21:00,000 --> 00:21:01,000
Let's print the item one by one.

433
00:21:01,000 --> 00:21:02,000
Right.

434
00:21:02,000 --> 00:21:08,000
So print item and here I'm just going to write end is equal to with a blank statement.

435
00:21:08,000 --> 00:21:14,000
So that whenever it is printing it should print um along with this blank a new line also.

436
00:21:14,000 --> 00:21:18,000
So now if I go ahead and execute see first tuple is basically getting printed one, two, three a,

437
00:21:18,000 --> 00:21:20,000
b, c and then true and false.

438
00:21:20,000 --> 00:21:22,000
So that is what I have right.

439
00:21:22,000 --> 00:21:28,000
So this was example with respect to uh tuples we have seen different different operations.

440
00:21:28,000 --> 00:21:30,000
We have seen about packing and packing.

441
00:21:31,000 --> 00:21:32,000
Uh we have seen the inbuilt methods.

442
00:21:32,000 --> 00:21:35,000
We have seen why do we get an error.

443
00:21:35,000 --> 00:21:36,000
What is mutable immutability.

444
00:21:37,000 --> 00:21:38,000
Everything we have actually seen.

445
00:21:38,000 --> 00:21:41,000
And we have also seen some of the examples with respect to uh, list.

446
00:21:41,000 --> 00:21:42,000
Right.

447
00:21:42,000 --> 00:21:50,000
But overall if you probably see like tuples are a kind of data structure, again, it will be specifically

448
00:21:50,000 --> 00:21:55,000
used when you do some kind of data analysis and all, uh, some or the other way, whenever you are

449
00:21:55,000 --> 00:21:59,000
writing the code and all, you will be using this tuple extensively.

450
00:21:59,000 --> 00:22:01,000
Now let me do one thing.

451
00:22:01,000 --> 00:22:06,000
Let me go ahead and finally write the conclusion so that you have this conclusion in mind where all

452
00:22:06,000 --> 00:22:12,000
tuples are tuples are versatile and very useful in various in many real world scenarios where an immutable

453
00:22:12,000 --> 00:22:14,000
and ordered collection of items is required.

454
00:22:14,000 --> 00:22:19,000
They are commonly used in data structure, function arguments, and return values as dictionary keys.

455
00:22:19,000 --> 00:22:23,000
Understanding how to leverage tuples effectively can improve the efficiency and readability of your

456
00:22:23,000 --> 00:22:26,000
Python codes, so I hope you like this particular video.

457
00:22:26,000 --> 00:22:28,000
This was it for my side.

458
00:22:28,000 --> 00:22:31,000
I will see you all in the next video, where we will be learning about the next data structure that

459
00:22:31,000 --> 00:22:32,000
is called as sets.

460
00:22:33,000 --> 00:22:33,000
Thank you.

461
00:22:33,000 --> 00:22:34,000
Take care.

462
00:22:34,000 --> 00:22:34,000
Bye bye.

