By turntables, so under the chapter, Python detectives who are going to define another new data type
that is known as the python tuples, so what is a python tuples in python tuples we got we are going
to define one tuple where the double elements will be enclosed within first brackets and tuple elements
can be having that heterogeneous data types.
So you might be asking me what is the difference between tuple?
And at least that list is mutable, but tuple elements are immutable that they cannot be updated.
So there is a basic difference between a couple and a list.
The list will be enclosed within two brackets.
That is a square brackets and tuples will be enclosed within our first brackets.
So let us go for the what are the different differences and features of tuples we're going to discuss
here.
So in many aspects, that tuple is similar to a list.
But the basic difference between the two is that we cannot change the elements of a tuple that is immutable
once it is assigned, whereas in a list the elements can be changed.
That list is mutable.
Advantages of over, at least snow falling at a certain advantages of implementing a table over a list
and below list are some of the main advantages.
So what are the advantages?
Why should they?
Why should a learn table here?
So we generally use tuple for heterogeneous different data types and for list it is generally for that
list will hold the homogeneous data, but obviously list can also hold that heterogeneous data type
elements.
But actually in general we use list to hold homogeneous data type data.
So since tables are immutable and iterating through a table is faster than with the list, so there
is a slight performance boost.
So as this table is immutable, so iterating through the table members will be a little bit faster.
So we are getting some boosting of the performances.
So tables that contain immutable elements can be used to as a key for a dictionary with list.
It is not possible because we know that in case of dictionary, the key values will be always unique
in nature.
So that's why, as in subtable, as it is immutable as a data, items cannot be changed to members of
the tuples cannot be changed, so therefore they cannot be updated.
So tables that contain immutable elements can be used as a key for one dictionary.
If you have data that does not change, implementing it as tuple will guarantee that it will remain
as in the read only mode.
So there are different building functions with the help of which you can we can do some processing of
the members of the tables.
So first one is the all return true if all elements of the table are to any return.
True, if any one of the elements of the table is true, enumerate, return and you might object.
It contains the index and the value of all the items of the table as peers.
Next to one is the Lenn, the return the length.
There is a number of items in the table.
Next one is a max return, the largest item in the table.
Next one is the minimum.
From the function itself, we are getting the purpose.
What is the purpose of the function?
So return the smallest item in the table.
Next one is the shortest.
Six elements in the table are returns, the new short list and next one is some return.
The sum of all elements in the table.
Next one is the table converts and iterable.
Least it might be the string, might be the set, might be the dictionary into a tuple.
So here we are having the type conversions.
So now let us go for one demonstration for the better, understanding how we can use and define and
operate with our table objects.
In Python programming, it is very much similar to a list.
That difference between the two is that we cannot change the elements of a table once it is assigned,
whereas in the list the elements can be changed.
That means list is mutable and tuple is immutable.
And now the difference here is that in case of list, we shall include other elements using third brackets
opening and closing, but will be including them using the opening and closing.
So there is another difference we are observing here.
So now let us discuss what are the advantages of of our list since tables of quite similar to list so
both of them can be used in similar situations as well.
And however, there are certain advantages of implementing it over the list.
So we can consider the first advantage as that we can generally use tuple for heterogeneous, different
data types, at least more homogeneous, that is, of the similar data types.
But in the previous video also we have shown you that list can take multiple different data type data,
but it is a common practice that wherever, wherever it will be using our variables of the different
types to be to be put in one structure, then in that in that case we be using the tuple.
But Ingersol list will be going for the homogeneous data types since Stupples are immutable.
So iterating through the table will be faster to some extent compared to that of the list.
So here we are getting some slight performance boosting so tuples can contain immutable items, elements
and can be used as a key for our dictionary.
So as a table, elements are immutable so it can contain the dictionary keys and which is not possible
in Cassopolis as it is mutable.
And if we have our data, which we do not want to change anymore, so we should implement it using tuple
because in the table will be will be keeping our data in a right protected format.
So here we are having one.
We are created and that is empty table.
So table one.
So it is empty.
If we print we are getting the output like this.
So now we are having this table.
We got initialized with this table to which some integer data will be there, elements will be there
in the tuple.
So it has got printed like this.
Here we are having the heterogeneous one that it made with the employee ID.
It may be the list, but the main brand name is employee salary and a department in which he or she
is working.
So that is our department is there.
So in this case, if we print the table three, we are getting the outcome like this.
Now, creation of Néstor couples now will be calling for the creation of the couples who can find that
this is it is a string, but this is a list and it is on the table here.
So one list has become the element of the table and another table, maybe the element of another table.
So printable for if you go on printing, we're getting the output like this.
So we know that lists will be included within square brackets and tables will be enclosed within brackets.
So that's why it is a table and it is a list.
So Topal can create can be created without any parentheses.
So now you can write this one, you can find that the tables are going to create here.
We have haven't enclose them within the past brackets, but the table has got created and it has got
printed tuple unpacking is also possible.
You know, that Inacceptable five were having one, two, three, four such a date.
So now we are going to assign them to employee ID, employee name in employee salary and employee department
so we can go on printing them.
I'm getting this employee ID, employee name, employee salary and also their employee department.
So the type of this table fight will be the class table.
So in this way we can have our list or a table as a members of another table.
Now we are going to access our elements, so how to do that one you see here we're defining one table
with this welcome characters and then print one.
We're getting this outcome like this.
So now table one one.
So this is my index.
So, you know, that index will be starting from zero.
So index one is this one.
So it is having the value eat.
So if I print that one, I'm getting it here.
Similarly for here for one three.
So zero one, two, three, Zorzi will get printed and here you are printing this five so zero one,
two, three, four, five.
So it has got printed here.
So now in that next case, we're having this next couple to we're having this point and this is one
Leavesden and another couple is there.
So if you go on printing this double to getting it printed now from the 08 element, you are picking
up the third character.
So from the zero element means the direct index means this one.
And from the third character means we're having this one be at the right place.
So this index is one.
This index is to this index is three.
So it will be printed and it has got printed accordingly and for the next couple to one two.
So that means we are considering this item number one, index number one in there.
And then two to means that this particular one is that index zero.
This two three is that index one and four is an index two here.
So that's why Ford has got printed here.
So Ford has got printed.
Next one is our next one is about double to two two.
So that means we are considering the second element and the second data.
So what is the value here?
So values nine here.
So it had the values nine.
So I'm getting here nine.
So in this way you can access elements from a table here.
So let's go for the next example now, slicing table contents.
So at first we are defined one table which is containing all the characters of the string.
Welcome.
So here we are going for the slicing.
So index number one, two, three.
So one column three means one, two, three, but three will be almost exclusive.
That dominating index that is up to which the index we are mentioning that is stopping index will be
always exclusive.
So here you can pick up the characters from the index one and two.
So index one is an index to Izell.
So accordingly, the values will be picked up.
So here to see we haven't mentioned the starting index, but the ending index will be minus three.
So this is my minus one, minus two, minus three.
So this one minus three.
So what will happen?
So always remember the ending index dominating index is always exclusive.
So it will bring all the members from index number zero to up to see here.
So that's why we are having this one as w, e, l, c.
So they have got printed now from starting from the index number three.
I haven't mentioned any dominating index it.
So index number three means zero, one, two, three.
So from here it will print up to the last element.
So that's why the outcome has come like this here, to see where we haven't mentioned any kind of starting
and stopping index values.
So that's why the full double will get printed here.
So that is a portable one.
So printable one one column three will produce the output like this, then minus three will produce
with this one because we are not mentioning the starting index.
So it will start from the very start and then it will proceed up to minus four.
So this is my minus one, minus two, minus three, add up to minus four.
This W, E, l, c will get printed and it has got printed.
Similarly, I expect the other cases now we are going for these elements which are immutable.
So as a result of that, after creating this particular table, so if we print the table, it will produce
output like this.
But if we go on updating its content, if we go on updating its content so it will produce one error
message, you can find that there is a type error.
So tuple object does not support item assignment.
So that's why it is producing one error and the name of the error is typewritten here.
OK, so now tuple can be reassigned, but you can assign a new tuple to this same one variable.
So you are having this printable one.
So this tuple one object has got initialized with the new tuple.
So that is not causing any problem.
But item a bit is not there is not allowed because it is it is about immutable.
So that's why if we go on printing now, you see the new tuple has got assigned to the one object.
Next one is a concatenation of the couples, so here to see we are printing this double two and three,
so now we are going for this concatenation using plus so you see table one content and then double the
content they have got concatenated in the same table.
So now here to see where having this particular table and this table will, I'm just multiplying it
by four.
That means four times this again will be there.
This particular string again will be there and that will produce one table.
So there is a syntax of writing.
Deletion operation on a table.
So here we are having one table here.
So if you go for delete two, then obviously it will produce some error Operation Y because you know
that that table is immutable.
So now what will happen if left unchecked?
This one, if we go on unchecked, so the error will be Opt-In is type error and that is double object
does not support item deletion.
So that is the message is getting printed.
So that's why I'm putting this one under command here so we can delete the entire table.
So tableful, so that full, full or whole tableful will get eliminated, will get deleted.
So in the index, if you print this table forward, it will print the name and name tableful is not
defined is a message.
So now we are having some trouble makers, so we're having some trouble makers, so five, we're having
this respect, all the characters are welcome and W5 got county.
So to count that, how many times this is orcharding here.
So I'm getting this one as to because it has got two times in this double.
So in the table members.
So now it is going for the index S..
So it will find out the occurrence, the index of the C character.
So this particular C string.
So that's why we are getting this through here, because it is index zero, index one index to an industry.
So now let me check if I have this C for adeptness.
If we have the C for another place, then what will happen if go executing?
I'm getting three back again because it will just check the first occurrence of this string C in this
particular table here.
So Topal operations.
So here we are having this stapel six, you can find it so double sixes there.
So now we can go for the print once.
So these are table six, see in table six seats there, so that's why it is giving me the outcome to
see not in table six outcome will be false in W6.
There is no is here.
So to return false, it not in W6, it will return true here.
So it is checking the set membership next one is the iteration through a couple elements.
So here you have a one table here where you find one table.
And if you go on using this for loop, that is four letters in table six.
We are printing these letters.
We're getting that for each and every iteration.
But just picking up one element from this table members and it has got assigned to these letters and
letters, letter letters is getting printed.
So now building functions with the tables.
So where do you find one table that Apple has got printed, Max, of the table seven.
So maximum element from this tuple.
So 77 has got printed minimum of table seven.
So here will be having the value element then shot at table seven.
So they'll be remaining in the shortened form.
The return one is in the list.
You can find that they are enclosed within square brackets and Lenn of table seven will give me that
count of the elements in the table available.
So in this way, we have discussed that.
What are the different operations?
What are the different functions that are inbuilt functions?
Are there with the help which we can operate on a table and also the difference between the list and
the table we have discussed in this session.
Thanks for watching this video.