1 00:00:00,240 --> 00:00:02,680 Changing a triple. 2 00:00:02,820 --> 00:00:12,270 We have just learned that tuples are immutable but it can contain mutable objects. 3 00:00:12,270 --> 00:00:13,710 Let us see an example. 4 00:00:14,460 --> 00:00:20,010 So consider a tuple which has de following elements. 5 00:00:20,100 --> 00:00:26,560 It also has a nested list which contains three elements. 6 00:00:26,560 --> 00:00:37,270 As we know a tuple is immutable whereas a list is mutable so we can change the element in the list. 7 00:00:37,270 --> 00:00:40,440 So how do we access the elements in the list. 8 00:00:42,220 --> 00:00:52,220 We can do this by indexing so the nested list has an index for and for example I want to change the 9 00:00:52,220 --> 00:00:56,390 element in the 0 8 position. 10 00:00:56,430 --> 00:01:01,210 This is going to retrieve the string a. 11 00:01:01,320 --> 00:01:09,840 Now I can go ahead and change this element to another string. 12 00:01:09,870 --> 00:01:12,740 That's because lists are mutable. 13 00:01:13,080 --> 00:01:15,660 So what is going to happen to the tuple. 14 00:01:15,660 --> 00:01:24,450 Is it still going to point to the same memory location or since one of the elements in the nested list 15 00:01:24,450 --> 00:01:25,700 has changed. 16 00:01:25,710 --> 00:01:36,100 Valid point to another memory address so let's verify this using the idea function in Jupiter notebook. 17 00:01:36,120 --> 00:01:46,860 Here we have a variable 2 3 which is assigned a tuple and this tuple Contains a nested list and before 18 00:01:46,860 --> 00:01:57,630 making any changes to any of these elements in the tuple let's check the memory address to which this 19 00:01:57,630 --> 00:02:00,030 variable is pointing to. 20 00:02:00,030 --> 00:02:07,530 So this is the memory address and before making any changes to the nested list here. 21 00:02:07,890 --> 00:02:20,930 I want to check the I.D. of this nested list so this would be 2 3 and the index is for so this nested 22 00:02:20,930 --> 00:02:24,080 list is pointing to this memory location. 23 00:02:24,080 --> 00:02:30,190 Now let us change one of the elements in the nested list. 24 00:02:30,620 --> 00:02:40,250 So I'm going to give the index number 4 and yo I want to change the element in the 0 8 index. 25 00:02:41,190 --> 00:02:43,590 To see another string. 26 00:02:43,620 --> 00:02:46,460 If so let us see. 27 00:02:46,460 --> 00:02:54,580 This assignment has changed the elements in the list so this assignment has changed. 28 00:02:54,690 --> 00:03:01,000 The first element in the list as you can see here it is F B and C are the elements. 29 00:03:01,180 --> 00:03:10,150 No now let us see if the list is still pointing to the all memory address. 30 00:03:10,310 --> 00:03:20,990 So 2 3 of or so as you can see the list is still pointing to the all memory location. 31 00:03:21,230 --> 00:03:26,110 That's because lists are changed in place. 32 00:03:26,110 --> 00:03:34,010 Whenever we make a change to a list add an element or delete an element or or change an element. 33 00:03:35,170 --> 00:03:37,150 A new list is not created. 34 00:03:37,210 --> 00:03:39,670 Lists are changed in play. 35 00:03:39,760 --> 00:03:41,860 So coming to the tuple. 36 00:03:41,890 --> 00:03:46,450 So how does it took a look now after the nested list has been changed. 37 00:03:46,450 --> 00:03:52,150 Here we have the tuple with the updated nested list. 38 00:03:52,750 --> 00:04:01,060 So let us check the memory location to which the tuple is pointing to. 39 00:04:01,090 --> 00:04:10,150 So this is the memory address to which it is pointing to after the changes have been made and this memory 40 00:04:10,150 --> 00:04:14,620 address is same as the one it is pointing to before the changes have been made. 41 00:04:14,620 --> 00:04:21,910 Now what would happen if we tried to change any of the other elements in the tuple Python has raised 42 00:04:21,910 --> 00:04:31,710 an exception as you can see it has raised a type road and it says the tuple object does not support 43 00:04:31,980 --> 00:04:44,390 item assignment meaning to build immutable objects we can use the plus operator to combine or concatenate 44 00:04:44,990 --> 00:04:46,090 tuples. 45 00:04:46,400 --> 00:04:56,030 And this is going to create a new tuple say for example we want to contact the native tuples to do an 46 00:04:57,050 --> 00:04:57,930 2 Three 47 00:05:00,700 --> 00:05:09,940 the new tuple that is created contains elements from both of these tuples the ones which are concatenated 48 00:05:10,450 --> 00:05:19,120 and we can also repeat the elements in a tuple specified number of times using this operator. 49 00:05:19,120 --> 00:05:28,340 And this is going to repeat these elements in the tuple two times as specified here. 50 00:05:28,410 --> 00:05:38,220 The output generated in this case is a new triple the original tuple does not change as you can see 51 00:05:38,220 --> 00:05:38,540 here. 52 00:05:38,550 --> 00:05:49,110 It only contains only five elements and the one here after the petition contains a total of 10.