0:00
Hello everyone, welcome to chapter 7. That is stuffies. So I will be explaining what are the tappell
0:04
data types in detail. Okay, so basically tupper is just like a list except that it is immutable
0:11
What is this mutable and immutable concept is? For example, I have a list A with the values
0:17
1-2 and 3. I can just go on and change the value of index 0 element to 4. And whenever I am
0:25
printing a it will output as 4 to 3 as a list but now similar way if at all I
0:33
wanted to do in tuple for example there is tuple 1 2 3 how I am defining double this is
0:40
list definition this is double definition you'll see how we'll define but in case
0:44
now we wanted to change the value of zero index to 5 we cannot do that why the
0:51
external from outside we cannot just go and change the values of the tuple so that
0:55
That's why Tuple is just a read only version of List. So now our data is fixed and never changes then we should go with Tupper
1:03
Insurgent order is preserved, duplicates are allowed heterogeneous. These are the same statement that we have seen in list
1:10
Apart from that, we can preserve the insert the insertion order and we can differentiate the duplicate
1:14
objects via indexes. For example if you have n number of same elements all of their indexes will be different So that why index we play important important role is in tuples as well Now whenever I am talking about indexes we have seen forward and backward
1:32
indexing, that means 0 1, 2 are positive index and minus 1, minus 2 from backward and minus 3 are
1:38
nothing but a negative index. A definition of tuple is inside round bracket with comma separated
1:44
values. Right. So we will see how to define the tuple. We can just simply define a double. We can just
1:49
simply define an identifier with an empty circular brackets. Also in case you wanted to add some value after the first value, contact you have to give
2:00
comma so that it will be considered as double. In case you do not want it to add parenthesis, you can simply write elements comma separated
2:08
It will also consider as a double and we have also seen the type casting how we have converted
2:13
a list or a string to list by using split method. Similar way we can convert list to tappel by using just tappell method on list
2:26
So it will be converting to tuple. Right. So these are the ways to define the tuple
2:30
Similar way, there are different functions that we have seen in the list as well
2:35
And strings are with like length function, we'll tell how many number of elements are there
2:38
in the tipple. Count of 40, it will count how many number of times 40 is there in tappel
2:44
Then index of 30 That means 0 2 and 3 so third in next and then sorted So it will just sort out the tuple with correct element in order
2:56
So this way even you can print the minimum and maximum from the tuples
3:01
So these are the outputs for these different method operations that we can perform on tipple
3:07
So this is one of the major questions that we have in our Python interviews
3:13
So round one most probably what is the difference between list and double. So double is immutable, list are mutable. This is first thing
3:20
Second it is defined by square bracket, sorry round brackets and these are defined by square brackets
3:27
Now since these are mutable, whatever the things that you wanted to change
3:33
or whenever you are using list these are kind of not that much passed in operation
3:40
rather than doubles. Right? Also, these are not used as keys in the dictionary. So in next chapters we'll see
3:48
whenever we are defining dictionaries, we are defining by a curly basis with key and value bear
3:53
So when we are talking about the keys, they must be immutable
3:57
Right. So because of that we cannot use list as a key, but we can use tappel as keys in dictionaries
4:05
So these are the top differences in list and tipple. We will see in a Jupiter notebook
4:10
Here we are just creating different ways of tuppel and whenever I being shift center you can see these are the different ways of creating the tuple Then we have to access the element we can do indexing and slicing
4:25
Similar way how we have seen in Linus and strings as in
4:29
Similarly, there are different functions and their examples. Outcount, index, sorted. Ming Mac is there and just doing Shift Enter just to give you the outputs of these schools
4:39
And then there is one more concept of double packing and unpacking
4:43
So that means whenever we are defining a different identifiers or variables with different values
4:49
you can combine all of them together in one value. Right. What I did, we know right
4:54
Without parenthesis also we can define a double. So I am just taking e comma B comma C comma D and assigning it to another identifier
5:01
or variable name thing. So now this T will be considered as tipple
5:06
And similar way you can unpack as well. For example, T is having multiple values
5:12
You can just take a number of variables which are equal to the values and assign it to T
5:19
All of those values one by one will get assigned to P, B, C and D
5:24
Whenever we are printing, so first we have printed combined values together by packing
5:30
and second one was the example of unpacking. So this is how double packing and unpacking works
5:36
So that is it from the top one. In the next chapter, we will see about