1 00:00:00,120 --> 00:00:06,840 Let us now discuss about the concept immutability in Python. 2 00:00:06,840 --> 00:00:08,980 The ready builds. 3 00:00:09,290 --> 00:00:10,900 Act like pointers. 4 00:00:11,020 --> 00:00:13,500 No other than containers. 5 00:00:13,500 --> 00:00:22,450 So what do we mean by this say for example in A C programming language when we assign a likelihood to 6 00:00:22,450 --> 00:00:29,200 a variable the variable functions like a container that stores do well. 7 00:00:29,620 --> 00:00:39,680 So this assignment actually creates a block of memory space so that it can hold the value for that relevant. 8 00:00:39,730 --> 00:00:52,770 Now let's create another way to win B read B and assign oh where double E to variable b and this assignment 9 00:00:54,130 --> 00:01:02,140 again create a block of memory space so that the variable B can hold the value in coming to the Python 10 00:01:02,140 --> 00:01:02,890 language 11 00:01:05,500 --> 00:01:15,430 here in Python we create available C by assigning a value twenty so we have just just cause that in 12 00:01:15,430 --> 00:01:27,020 Python the variables act as point does to the memory locations the variable C will bind to a memory 13 00:01:27,020 --> 00:01:40,910 location which contains the value twenty now let's define another variable D which is now assigned to 14 00:01:41,400 --> 00:01:43,170 where the B C. 15 00:01:43,490 --> 00:01:47,020 So what does this mean in python in python. 16 00:01:47,210 --> 00:01:57,380 This assignment here means variable D point to the same value to which variable C is pointing to the 17 00:01:57,410 --> 00:02:07,940 variable C and variable D are pointing to the same memory location now as part of the program say we 18 00:02:07,940 --> 00:02:18,000 have assigned a new low to the variability C variable C now is equal to 40. 19 00:02:18,210 --> 00:02:20,540 So what does Python do now. 20 00:02:20,730 --> 00:02:25,410 Does it change the value in this particular memory location. 21 00:02:25,470 --> 00:02:25,950 No 22 00:02:28,770 --> 00:02:38,610 Python now makes the pointer variable C to point to the new value forty that is debatable D is still 23 00:02:38,820 --> 00:02:49,320 pointing to the old value twenty so the content in the memory location are not changed. 24 00:02:49,580 --> 00:02:56,260 The pointer is now pointing to a different memory location after the new assignment. 25 00:02:57,320 --> 00:03:07,590 So the content of the objects of immutable data types can not be changed after the ad created so this 26 00:03:07,590 --> 00:03:14,490 is about immutability of all these data types integer and flawed. 27 00:03:15,450 --> 00:03:24,180 So here I am taking a variable C which is binding to devalue 10. 28 00:03:24,420 --> 00:03:28,570 Now execute do code in this setting. 29 00:03:28,800 --> 00:03:33,330 By hitting shift and into these next 30 00:03:35,930 --> 00:03:42,790 I would like to check the memory location to which the pointer C is pointing to. 31 00:03:42,800 --> 00:03:48,610 So let's use the built in function idea and enter the object. 32 00:03:48,620 --> 00:03:52,980 See execute descent. 33 00:03:53,330 --> 00:03:56,520 So this is the memory location it is pointing to. 34 00:03:56,670 --> 00:04:04,310 Now let define another variable which has the same value as C.. 35 00:04:04,370 --> 00:04:12,320 That means the DNC should point to the same memory location containing value 10. 36 00:04:12,410 --> 00:04:17,090 Now let's verify that again I D. 37 00:04:17,550 --> 00:04:25,880 Or D So or C and D are pointing to the same memory location. 38 00:04:25,890 --> 00:04:35,440 Now let's change the value or for the variability to 20 executed and then 39 00:04:38,250 --> 00:04:42,440 check for the memory location. 40 00:04:42,520 --> 00:04:50,950 So as you can see this memory location is different from what D pointing to so is D still pointing to 41 00:04:51,070 --> 00:04:58,310 10 or is it pointing to the new value that is 20. 42 00:04:58,630 --> 00:04:59,680 Let's check that 43 00:05:03,670 --> 00:05:09,550 so D is still pointing to the value 10 as you can see here. 44 00:05:13,460 --> 00:05:21,740 But C is now pointing to the value 20 which is in this particular memory location. 45 00:05:21,740 --> 00:05:30,140 So something is mutable only when we are able to change these values held in the memory location without 46 00:05:30,140 --> 00:05:32,620 changing the memory location itself. 47 00:05:32,810 --> 00:05:40,580 But another example then we have assigned a different value to the variable C it points to a different 48 00:05:40,580 --> 00:05:51,430 memory location containing the new value so this means building data types like integer flawed etc. 49 00:05:51,930 --> 00:05:57,580 are immutable will see a few more examples of strings as well. 50 00:05:58,120 --> 00:05:58,840 Shortly.