1 00:00:00,360 --> 00:00:07,010 By turntables, so under the chapter, Python detectives who are going to define another new data type 2 00:00:07,020 --> 00:00:13,530 that is known as the python tuples, so what is a python tuples in python tuples we got we are going 3 00:00:13,530 --> 00:00:20,550 to define one tuple where the double elements will be enclosed within first brackets and tuple elements 4 00:00:20,730 --> 00:00:23,840 can be having that heterogeneous data types. 5 00:00:24,240 --> 00:00:26,910 So you might be asking me what is the difference between tuple? 6 00:00:26,910 --> 00:00:34,240 And at least that list is mutable, but tuple elements are immutable that they cannot be updated. 7 00:00:34,380 --> 00:00:38,010 So there is a basic difference between a couple and a list. 8 00:00:38,190 --> 00:00:40,380 The list will be enclosed within two brackets. 9 00:00:40,440 --> 00:00:45,680 That is a square brackets and tuples will be enclosed within our first brackets. 10 00:00:46,230 --> 00:00:52,260 So let us go for the what are the different differences and features of tuples we're going to discuss 11 00:00:52,260 --> 00:00:52,450 here. 12 00:00:52,830 --> 00:00:55,890 So in many aspects, that tuple is similar to a list. 13 00:00:56,490 --> 00:01:03,390 But the basic difference between the two is that we cannot change the elements of a tuple that is immutable 14 00:01:03,600 --> 00:01:07,820 once it is assigned, whereas in a list the elements can be changed. 15 00:01:07,980 --> 00:01:09,900 That list is mutable. 16 00:01:12,320 --> 00:01:19,760 Advantages of over, at least snow falling at a certain advantages of implementing a table over a list 17 00:01:20,030 --> 00:01:22,490 and below list are some of the main advantages. 18 00:01:22,520 --> 00:01:23,740 So what are the advantages? 19 00:01:23,750 --> 00:01:24,330 Why should they? 20 00:01:24,590 --> 00:01:26,090 Why should a learn table here? 21 00:01:26,540 --> 00:01:34,280 So we generally use tuple for heterogeneous different data types and for list it is generally for that 22 00:01:34,280 --> 00:01:40,450 list will hold the homogeneous data, but obviously list can also hold that heterogeneous data type 23 00:01:40,490 --> 00:01:41,060 elements. 24 00:01:41,270 --> 00:01:46,940 But actually in general we use list to hold homogeneous data type data. 25 00:01:47,660 --> 00:01:54,530 So since tables are immutable and iterating through a table is faster than with the list, so there 26 00:01:54,530 --> 00:01:56,670 is a slight performance boost. 27 00:01:57,110 --> 00:02:03,170 So as this table is immutable, so iterating through the table members will be a little bit faster. 28 00:02:03,170 --> 00:02:05,620 So we are getting some boosting of the performances. 29 00:02:06,170 --> 00:02:12,580 So tables that contain immutable elements can be used to as a key for a dictionary with list. 30 00:02:12,590 --> 00:02:18,530 It is not possible because we know that in case of dictionary, the key values will be always unique 31 00:02:18,530 --> 00:02:19,040 in nature. 32 00:02:19,220 --> 00:02:25,340 So that's why, as in subtable, as it is immutable as a data, items cannot be changed to members of 33 00:02:25,340 --> 00:02:28,450 the tuples cannot be changed, so therefore they cannot be updated. 34 00:02:28,550 --> 00:02:34,190 So tables that contain immutable elements can be used as a key for one dictionary. 35 00:02:35,420 --> 00:02:42,260 If you have data that does not change, implementing it as tuple will guarantee that it will remain 36 00:02:42,290 --> 00:02:44,540 as in the read only mode. 37 00:02:46,120 --> 00:02:50,770 So there are different building functions with the help of which you can we can do some processing of 38 00:02:50,770 --> 00:02:52,320 the members of the tables. 39 00:02:52,480 --> 00:02:58,750 So first one is the all return true if all elements of the table are to any return. 40 00:02:58,750 --> 00:03:05,470 True, if any one of the elements of the table is true, enumerate, return and you might object. 41 00:03:05,500 --> 00:03:11,160 It contains the index and the value of all the items of the table as peers. 42 00:03:11,470 --> 00:03:14,410 Next to one is the Lenn, the return the length. 43 00:03:14,410 --> 00:03:16,990 There is a number of items in the table. 44 00:03:17,350 --> 00:03:21,800 Next one is a max return, the largest item in the table. 45 00:03:22,180 --> 00:03:23,230 Next one is the minimum. 46 00:03:23,230 --> 00:03:25,280 From the function itself, we are getting the purpose. 47 00:03:25,300 --> 00:03:26,620 What is the purpose of the function? 48 00:03:26,950 --> 00:03:30,370 So return the smallest item in the table. 49 00:03:30,490 --> 00:03:31,620 Next one is the shortest. 50 00:03:31,810 --> 00:03:38,020 Six elements in the table are returns, the new short list and next one is some return. 51 00:03:38,020 --> 00:03:40,570 The sum of all elements in the table. 52 00:03:40,720 --> 00:03:43,660 Next one is the table converts and iterable. 53 00:03:43,810 --> 00:03:49,060 Least it might be the string, might be the set, might be the dictionary into a tuple. 54 00:03:49,060 --> 00:03:51,250 So here we are having the type conversions. 55 00:03:51,670 --> 00:03:57,490 So now let us go for one demonstration for the better, understanding how we can use and define and 56 00:03:57,490 --> 00:03:59,860 operate with our table objects. 57 00:04:00,490 --> 00:04:04,810 In Python programming, it is very much similar to a list. 58 00:04:05,290 --> 00:04:10,840 That difference between the two is that we cannot change the elements of a table once it is assigned, 59 00:04:10,840 --> 00:04:13,950 whereas in the list the elements can be changed. 60 00:04:13,960 --> 00:04:17,740 That means list is mutable and tuple is immutable. 61 00:04:18,040 --> 00:04:24,460 And now the difference here is that in case of list, we shall include other elements using third brackets 62 00:04:24,460 --> 00:04:30,240 opening and closing, but will be including them using the opening and closing. 63 00:04:30,370 --> 00:04:32,410 So there is another difference we are observing here. 64 00:04:32,620 --> 00:04:39,550 So now let us discuss what are the advantages of of our list since tables of quite similar to list so 65 00:04:39,550 --> 00:04:43,120 both of them can be used in similar situations as well. 66 00:04:43,720 --> 00:04:48,790 And however, there are certain advantages of implementing it over the list. 67 00:04:49,210 --> 00:04:55,720 So we can consider the first advantage as that we can generally use tuple for heterogeneous, different 68 00:04:55,720 --> 00:04:59,890 data types, at least more homogeneous, that is, of the similar data types. 69 00:04:59,890 --> 00:05:05,890 But in the previous video also we have shown you that list can take multiple different data type data, 70 00:05:06,280 --> 00:05:11,320 but it is a common practice that wherever, wherever it will be using our variables of the different 71 00:05:11,560 --> 00:05:17,530 types to be to be put in one structure, then in that in that case we be using the tuple. 72 00:05:17,890 --> 00:05:24,010 But Ingersol list will be going for the homogeneous data types since Stupples are immutable. 73 00:05:24,010 --> 00:05:29,380 So iterating through the table will be faster to some extent compared to that of the list. 74 00:05:29,590 --> 00:05:36,910 So here we are getting some slight performance boosting so tuples can contain immutable items, elements 75 00:05:37,120 --> 00:05:40,090 and can be used as a key for our dictionary. 76 00:05:40,090 --> 00:05:46,780 So as a table, elements are immutable so it can contain the dictionary keys and which is not possible 77 00:05:46,780 --> 00:05:49,030 in Cassopolis as it is mutable. 78 00:05:49,600 --> 00:05:56,260 And if we have our data, which we do not want to change anymore, so we should implement it using tuple 79 00:05:56,380 --> 00:06:02,040 because in the table will be will be keeping our data in a right protected format. 80 00:06:02,590 --> 00:06:04,120 So here we are having one. 81 00:06:04,570 --> 00:06:07,090 We are created and that is empty table. 82 00:06:07,130 --> 00:06:08,050 So table one. 83 00:06:08,470 --> 00:06:09,310 So it is empty. 84 00:06:09,610 --> 00:06:11,470 If we print we are getting the output like this. 85 00:06:11,800 --> 00:06:13,350 So now we are having this table. 86 00:06:13,480 --> 00:06:19,990 We got initialized with this table to which some integer data will be there, elements will be there 87 00:06:19,990 --> 00:06:20,590 in the tuple. 88 00:06:20,830 --> 00:06:22,510 So it has got printed like this. 89 00:06:22,750 --> 00:06:27,250 Here we are having the heterogeneous one that it made with the employee ID. 90 00:06:27,250 --> 00:06:32,980 It may be the list, but the main brand name is employee salary and a department in which he or she 91 00:06:32,980 --> 00:06:33,520 is working. 92 00:06:33,520 --> 00:06:36,280 So that is our department is there. 93 00:06:36,640 --> 00:06:40,450 So in this case, if we print the table three, we are getting the outcome like this. 94 00:06:42,360 --> 00:06:47,400 Now, creation of Néstor couples now will be calling for the creation of the couples who can find that 95 00:06:47,730 --> 00:06:52,480 this is it is a string, but this is a list and it is on the table here. 96 00:06:52,830 --> 00:06:58,610 So one list has become the element of the table and another table, maybe the element of another table. 97 00:06:58,980 --> 00:07:02,820 So printable for if you go on printing, we're getting the output like this. 98 00:07:02,820 --> 00:07:08,750 So we know that lists will be included within square brackets and tables will be enclosed within brackets. 99 00:07:08,760 --> 00:07:11,160 So that's why it is a table and it is a list. 100 00:07:11,760 --> 00:07:15,310 So Topal can create can be created without any parentheses. 101 00:07:15,330 --> 00:07:20,310 So now you can write this one, you can find that the tables are going to create here. 102 00:07:20,610 --> 00:07:26,280 We have haven't enclose them within the past brackets, but the table has got created and it has got 103 00:07:26,280 --> 00:07:29,730 printed tuple unpacking is also possible. 104 00:07:29,730 --> 00:07:34,320 You know, that Inacceptable five were having one, two, three, four such a date. 105 00:07:35,070 --> 00:07:42,000 So now we are going to assign them to employee ID, employee name in employee salary and employee department 106 00:07:42,180 --> 00:07:43,730 so we can go on printing them. 107 00:07:43,740 --> 00:07:49,200 I'm getting this employee ID, employee name, employee salary and also their employee department. 108 00:07:49,650 --> 00:07:53,050 So the type of this table fight will be the class table. 109 00:07:53,520 --> 00:07:59,760 So in this way we can have our list or a table as a members of another table. 110 00:08:02,120 --> 00:08:08,500 Now we are going to access our elements, so how to do that one you see here we're defining one table 111 00:08:08,540 --> 00:08:12,520 with this welcome characters and then print one. 112 00:08:12,530 --> 00:08:14,140 We're getting this outcome like this. 113 00:08:14,450 --> 00:08:15,780 So now table one one. 114 00:08:15,800 --> 00:08:17,150 So this is my index. 115 00:08:17,420 --> 00:08:19,800 So, you know, that index will be starting from zero. 116 00:08:20,240 --> 00:08:22,070 So index one is this one. 117 00:08:22,100 --> 00:08:23,380 So it is having the value eat. 118 00:08:23,570 --> 00:08:25,870 So if I print that one, I'm getting it here. 119 00:08:25,880 --> 00:08:29,180 Similarly for here for one three. 120 00:08:29,360 --> 00:08:36,020 So zero one, two, three, Zorzi will get printed and here you are printing this five so zero one, 121 00:08:36,020 --> 00:08:37,730 two, three, four, five. 122 00:08:37,910 --> 00:08:39,530 So it has got printed here. 123 00:08:40,040 --> 00:08:45,920 So now in that next case, we're having this next couple to we're having this point and this is one 124 00:08:45,920 --> 00:08:48,020 Leavesden and another couple is there. 125 00:08:48,440 --> 00:08:55,070 So if you go on printing this double to getting it printed now from the 08 element, you are picking 126 00:08:55,070 --> 00:08:56,860 up the third character. 127 00:08:56,870 --> 00:09:00,560 So from the zero element means the direct index means this one. 128 00:09:00,830 --> 00:09:05,110 And from the third character means we're having this one be at the right place. 129 00:09:05,450 --> 00:09:07,190 So this index is one. 130 00:09:07,190 --> 00:09:09,410 This index is to this index is three. 131 00:09:09,560 --> 00:09:16,120 So it will be printed and it has got printed accordingly and for the next couple to one two. 132 00:09:16,130 --> 00:09:20,300 So that means we are considering this item number one, index number one in there. 133 00:09:20,570 --> 00:09:24,470 And then two to means that this particular one is that index zero. 134 00:09:24,480 --> 00:09:29,020 This two three is that index one and four is an index two here. 135 00:09:29,030 --> 00:09:30,760 So that's why Ford has got printed here. 136 00:09:31,040 --> 00:09:32,180 So Ford has got printed. 137 00:09:32,720 --> 00:09:36,680 Next one is our next one is about double to two two. 138 00:09:36,980 --> 00:09:41,030 So that means we are considering the second element and the second data. 139 00:09:41,040 --> 00:09:42,050 So what is the value here? 140 00:09:42,050 --> 00:09:43,150 So values nine here. 141 00:09:43,160 --> 00:09:44,210 So it had the values nine. 142 00:09:44,420 --> 00:09:45,450 So I'm getting here nine. 143 00:09:45,800 --> 00:09:49,100 So in this way you can access elements from a table here. 144 00:09:49,520 --> 00:09:54,700 So let's go for the next example now, slicing table contents. 145 00:09:54,710 --> 00:09:59,240 So at first we are defined one table which is containing all the characters of the string. 146 00:09:59,250 --> 00:09:59,670 Welcome. 147 00:10:00,500 --> 00:10:02,510 So here we are going for the slicing. 148 00:10:02,510 --> 00:10:04,260 So index number one, two, three. 149 00:10:04,490 --> 00:10:09,280 So one column three means one, two, three, but three will be almost exclusive. 150 00:10:09,770 --> 00:10:15,890 That dominating index that is up to which the index we are mentioning that is stopping index will be 151 00:10:15,900 --> 00:10:16,820 always exclusive. 152 00:10:16,850 --> 00:10:20,600 So here you can pick up the characters from the index one and two. 153 00:10:20,960 --> 00:10:23,720 So index one is an index to Izell. 154 00:10:23,720 --> 00:10:26,280 So accordingly, the values will be picked up. 155 00:10:26,840 --> 00:10:31,720 So here to see we haven't mentioned the starting index, but the ending index will be minus three. 156 00:10:32,150 --> 00:10:35,540 So this is my minus one, minus two, minus three. 157 00:10:35,540 --> 00:10:36,810 So this one minus three. 158 00:10:37,070 --> 00:10:37,990 So what will happen? 159 00:10:38,270 --> 00:10:42,630 So always remember the ending index dominating index is always exclusive. 160 00:10:42,860 --> 00:10:47,770 So it will bring all the members from index number zero to up to see here. 161 00:10:47,990 --> 00:10:52,130 So that's why we are having this one as w, e, l, c. 162 00:10:52,130 --> 00:10:55,960 So they have got printed now from starting from the index number three. 163 00:10:55,970 --> 00:10:58,460 I haven't mentioned any dominating index it. 164 00:10:58,820 --> 00:11:01,590 So index number three means zero, one, two, three. 165 00:11:01,700 --> 00:11:04,700 So from here it will print up to the last element. 166 00:11:04,710 --> 00:11:10,790 So that's why the outcome has come like this here, to see where we haven't mentioned any kind of starting 167 00:11:10,790 --> 00:11:12,290 and stopping index values. 168 00:11:12,500 --> 00:11:15,300 So that's why the full double will get printed here. 169 00:11:15,710 --> 00:11:17,200 So that is a portable one. 170 00:11:17,210 --> 00:11:23,930 So printable one one column three will produce the output like this, then minus three will produce 171 00:11:24,080 --> 00:11:26,810 with this one because we are not mentioning the starting index. 172 00:11:27,020 --> 00:11:31,990 So it will start from the very start and then it will proceed up to minus four. 173 00:11:32,360 --> 00:11:37,330 So this is my minus one, minus two, minus three, add up to minus four. 174 00:11:37,520 --> 00:11:41,480 This W, E, l, c will get printed and it has got printed. 175 00:11:41,720 --> 00:11:48,290 Similarly, I expect the other cases now we are going for these elements which are immutable. 176 00:11:48,290 --> 00:11:53,750 So as a result of that, after creating this particular table, so if we print the table, it will produce 177 00:11:53,750 --> 00:11:54,560 output like this. 178 00:11:54,860 --> 00:12:01,820 But if we go on updating its content, if we go on updating its content so it will produce one error 179 00:12:01,820 --> 00:12:04,250 message, you can find that there is a type error. 180 00:12:04,430 --> 00:12:07,790 So tuple object does not support item assignment. 181 00:12:08,060 --> 00:12:12,890 So that's why it is producing one error and the name of the error is typewritten here. 182 00:12:13,490 --> 00:12:22,120 OK, so now tuple can be reassigned, but you can assign a new tuple to this same one variable. 183 00:12:22,220 --> 00:12:24,290 So you are having this printable one. 184 00:12:24,290 --> 00:12:28,610 So this tuple one object has got initialized with the new tuple. 185 00:12:28,880 --> 00:12:30,860 So that is not causing any problem. 186 00:12:30,860 --> 00:12:36,860 But item a bit is not there is not allowed because it is it is about immutable. 187 00:12:37,310 --> 00:12:42,800 So that's why if we go on printing now, you see the new tuple has got assigned to the one object. 188 00:12:44,130 --> 00:12:49,740 Next one is a concatenation of the couples, so here to see we are printing this double two and three, 189 00:12:50,220 --> 00:12:55,380 so now we are going for this concatenation using plus so you see table one content and then double the 190 00:12:55,380 --> 00:12:58,140 content they have got concatenated in the same table. 191 00:12:58,680 --> 00:13:04,020 So now here to see where having this particular table and this table will, I'm just multiplying it 192 00:13:04,020 --> 00:13:04,440 by four. 193 00:13:04,450 --> 00:13:06,990 That means four times this again will be there. 194 00:13:07,290 --> 00:13:10,850 This particular string again will be there and that will produce one table. 195 00:13:11,100 --> 00:13:12,840 So there is a syntax of writing. 196 00:13:15,220 --> 00:13:16,870 Deletion operation on a table. 197 00:13:16,900 --> 00:13:18,530 So here we are having one table here. 198 00:13:19,330 --> 00:13:26,260 So if you go for delete two, then obviously it will produce some error Operation Y because you know 199 00:13:26,260 --> 00:13:28,970 that that table is immutable. 200 00:13:28,990 --> 00:13:31,390 So now what will happen if left unchecked? 201 00:13:31,390 --> 00:13:37,630 This one, if we go on unchecked, so the error will be Opt-In is type error and that is double object 202 00:13:37,630 --> 00:13:39,660 does not support item deletion. 203 00:13:39,670 --> 00:13:41,430 So that is the message is getting printed. 204 00:13:42,130 --> 00:13:46,920 So that's why I'm putting this one under command here so we can delete the entire table. 205 00:13:46,960 --> 00:13:53,970 So tableful, so that full, full or whole tableful will get eliminated, will get deleted. 206 00:13:54,310 --> 00:14:01,480 So in the index, if you print this table forward, it will print the name and name tableful is not 207 00:14:01,480 --> 00:14:02,830 defined is a message. 208 00:14:06,520 --> 00:14:12,490 So now we are having some trouble makers, so we're having some trouble makers, so five, we're having 209 00:14:12,490 --> 00:14:17,170 this respect, all the characters are welcome and W5 got county. 210 00:14:17,170 --> 00:14:20,560 So to count that, how many times this is orcharding here. 211 00:14:20,560 --> 00:14:25,330 So I'm getting this one as to because it has got two times in this double. 212 00:14:25,690 --> 00:14:26,950 So in the table members. 213 00:14:27,040 --> 00:14:29,010 So now it is going for the index S.. 214 00:14:29,020 --> 00:14:33,110 So it will find out the occurrence, the index of the C character. 215 00:14:33,340 --> 00:14:34,720 So this particular C string. 216 00:14:35,200 --> 00:14:40,660 So that's why we are getting this through here, because it is index zero, index one index to an industry. 217 00:14:41,050 --> 00:14:44,960 So now let me check if I have this C for adeptness. 218 00:14:44,980 --> 00:14:48,790 If we have the C for another place, then what will happen if go executing? 219 00:14:48,880 --> 00:14:55,390 I'm getting three back again because it will just check the first occurrence of this string C in this 220 00:14:55,390 --> 00:14:56,380 particular table here. 221 00:14:58,890 --> 00:15:00,340 So Topal operations. 222 00:15:00,630 --> 00:15:05,050 So here we are having this stapel six, you can find it so double sixes there. 223 00:15:05,340 --> 00:15:07,350 So now we can go for the print once. 224 00:15:13,400 --> 00:15:20,120 So these are table six, see in table six seats there, so that's why it is giving me the outcome to 225 00:15:20,600 --> 00:15:25,030 see not in table six outcome will be false in W6. 226 00:15:25,040 --> 00:15:26,300 There is no is here. 227 00:15:26,450 --> 00:15:30,680 So to return false, it not in W6, it will return true here. 228 00:15:33,200 --> 00:15:38,410 So it is checking the set membership next one is the iteration through a couple elements. 229 00:15:38,750 --> 00:15:41,870 So here you have a one table here where you find one table. 230 00:15:42,110 --> 00:15:47,630 And if you go on using this for loop, that is four letters in table six. 231 00:15:47,780 --> 00:15:49,130 We are printing these letters. 232 00:15:49,130 --> 00:15:51,200 We're getting that for each and every iteration. 233 00:15:51,470 --> 00:15:58,220 But just picking up one element from this table members and it has got assigned to these letters and 234 00:15:58,220 --> 00:16:00,770 letters, letter letters is getting printed. 235 00:16:02,120 --> 00:16:04,550 So now building functions with the tables. 236 00:16:05,330 --> 00:16:09,850 So where do you find one table that Apple has got printed, Max, of the table seven. 237 00:16:09,860 --> 00:16:12,530 So maximum element from this tuple. 238 00:16:12,530 --> 00:16:15,550 So 77 has got printed minimum of table seven. 239 00:16:15,920 --> 00:16:19,910 So here will be having the value element then shot at table seven. 240 00:16:19,920 --> 00:16:22,400 So they'll be remaining in the shortened form. 241 00:16:22,640 --> 00:16:25,030 The return one is in the list. 242 00:16:25,040 --> 00:16:31,030 You can find that they are enclosed within square brackets and Lenn of table seven will give me that 243 00:16:31,040 --> 00:16:33,930 count of the elements in the table available. 244 00:16:34,400 --> 00:16:36,050 So in this way, we have discussed that. 245 00:16:36,050 --> 00:16:37,580 What are the different operations? 246 00:16:37,580 --> 00:16:40,220 What are the different functions that are inbuilt functions? 247 00:16:40,220 --> 00:16:45,860 Are there with the help which we can operate on a table and also the difference between the list and 248 00:16:45,860 --> 00:16:48,200 the table we have discussed in this session. 249 00:16:48,560 --> 00:16:49,730 Thanks for watching this video.