1 00:00:00,360 --> 00:00:07,260 Coming to the list of variables and the use references now variables to list differently, then they 2 00:00:07,260 --> 00:00:13,320 store other values of variable, will contain a reference to the list rather than the list itself. 3 00:00:13,650 --> 00:00:20,070 A reference is just a value that points to some bit of data, and the list of reference is a value that 4 00:00:20,070 --> 00:00:21,180 points to the list. 5 00:00:21,510 --> 00:00:24,800 So this results in slightly different behavior of your code. 6 00:00:25,200 --> 00:00:31,440 Now that you know, what are the variable store strings and integer values, we would enter certain 7 00:00:31,560 --> 00:00:34,620 commands in the interactive shell and check the output. 8 00:00:34,980 --> 00:00:41,250 For example, we'll go back here and let us try to type this pan equals two forty two. 9 00:00:41,250 --> 00:00:46,310 For example, say cheese equal to the value of spane. 10 00:00:47,160 --> 00:00:52,440 Let's give spinn equals two hundred and let's try to put in the value of spane. 11 00:00:52,740 --> 00:00:54,930 Oh sorry we made a mistake. 12 00:00:55,140 --> 00:01:01,650 Spinous forty two cheese equal to span span equal two hundred. 13 00:01:02,190 --> 00:01:04,650 And now let's print so we get the value hundred. 14 00:01:05,100 --> 00:01:07,890 Now let's try to put in the value of cheese a still forty two. 15 00:01:07,890 --> 00:01:15,090 So we have assigned forty two to the first span variable and then we copy that value of the span and 16 00:01:15,090 --> 00:01:16,620 assign it to the variable cheese. 17 00:01:16,860 --> 00:01:20,910 So then we later change the value and spend two hundred on new number. 18 00:01:20,910 --> 00:01:27,450 Doesn't affect the value in the cheese variable because PiƱon choose a totally different variables that 19 00:01:27,450 --> 00:01:29,160 store different values. 20 00:01:29,310 --> 00:01:32,100 But list doesn't work this way. 21 00:01:32,460 --> 00:01:37,650 When we assign a list to a variable, we are actually assigning a list reference to the variable. 22 00:01:37,950 --> 00:01:43,410 So if we try to make certain code that makes the distinction easier to understand. 23 00:01:43,650 --> 00:01:53,040 For example, we try to make the list one that's equal to we give here certain values in the list. 24 00:01:53,190 --> 00:01:55,200 OK, one, two, seven, for example. 25 00:01:55,650 --> 00:02:01,380 And then we create C red one that's equal to forgive list one. 26 00:02:02,190 --> 00:02:05,700 Then we try to make where one at the index one. 27 00:02:06,120 --> 00:02:13,670 We try to give there some text C that's right down by ten for example. 28 00:02:14,070 --> 00:02:20,190 And now let's try to print the value of list one you see in list one. 29 00:02:20,190 --> 00:02:25,440 Also it has changed and if we try to print the value through variable, even where one has changed, 30 00:02:25,680 --> 00:02:33,170 so this code might look old to you, the chord changes or change, not only the variable that is very 31 00:02:33,180 --> 00:02:37,130 one, but both were one and the list one values also. 32 00:02:37,470 --> 00:02:41,790 So when we create a list, we assign a reference to it in the variable. 33 00:02:42,030 --> 00:02:48,180 But in the next line we have copied only the list of difference in the variable that is variable or 34 00:02:48,450 --> 00:02:51,020 list one to variable, not the list value. 35 00:02:51,030 --> 00:02:57,540 This means that the value stored in the list one and let one now both refer to the same list. 36 00:02:57,900 --> 00:03:02,690 So there is only one underlying list because the actual list was never actually copied. 37 00:03:03,060 --> 00:03:07,080 So then we modify the first element of the word one variable. 38 00:03:07,080 --> 00:03:11,370 We're actually modifying the same list that list one refers to. 39 00:03:11,880 --> 00:03:15,300 Let us understand another concept that is passing references. 40 00:03:15,600 --> 00:03:22,080 No references are particularly important for understanding how arguments are passed to the functions 41 00:03:22,080 --> 00:03:22,710 or methods. 42 00:03:23,010 --> 00:03:30,000 When a function is called the argument, values are copied to the parameter values and for list this 43 00:03:30,000 --> 00:03:33,330 means a copy of a reference is used for the parameter. 44 00:03:33,780 --> 00:03:39,000 Now, to see the consequences of this action, we will create a new file and we would enter certain 45 00:03:39,000 --> 00:03:41,790 code into it and then try to execute it. 46 00:03:42,030 --> 00:03:44,820 So let us go back here and see a new file. 47 00:03:45,120 --> 00:03:47,580 We will define a particular matter. 48 00:03:47,880 --> 00:03:50,580 See dummy one. 49 00:03:51,000 --> 00:04:03,630 In this we are giving parameter one and in this particular matter we are seeing parameter one up and 50 00:04:04,380 --> 00:04:07,410 see Biton as a text. 51 00:04:08,160 --> 00:04:14,700 After this we come back here, we create a list, one that's equal to say, one, two, three. 52 00:04:15,030 --> 00:04:16,170 Some values are given. 53 00:04:16,500 --> 00:04:20,730 Then we call that the method that is number one. 54 00:04:21,000 --> 00:04:29,560 And we pass this list one as the parameter to it, and then we try to print the value of the list. 55 00:04:31,260 --> 00:04:36,450 Now, let us save this as C demo fifteen thought B vi. 56 00:04:36,630 --> 00:04:42,390 That's E drive HACKENBUSH and let us try to run this. 57 00:04:42,870 --> 00:04:46,970 So we are getting one, two, three and plus one more value is appended to it. 58 00:04:47,250 --> 00:04:49,200 So then you run the particular course. 59 00:04:49,200 --> 00:04:56,010 We have noticed that the metadata Skold return value isn't used to assign a new value to the variable 60 00:04:56,010 --> 00:04:57,090 that we have created. 61 00:04:57,390 --> 00:04:59,790 Instead, a list is modified directly. 62 00:05:00,010 --> 00:05:06,430 So when we ran the program, we get the value as one, two, three come up bitin, even though we are 63 00:05:06,430 --> 00:05:08,110 having two different variables. 64 00:05:08,350 --> 00:05:14,920 One is if we look at our program, one is our list one and one is the parameter that this parameter, 65 00:05:14,920 --> 00:05:20,020 one that contains separate references, they both refer to the same list. 66 00:05:20,290 --> 00:05:27,010 Now, this is why the append Biton matter called inside the function of the list, even after the function 67 00:05:27,010 --> 00:05:28,330 call has a record. 68 00:05:28,690 --> 00:05:30,400 So keep this behavior in mind. 69 00:05:30,400 --> 00:05:37,390 Forgetting that Biton handles list, variables this way can lead to some confusing box succumbing to 70 00:05:37,390 --> 00:05:41,920 using the copy poppy to duplicate a particular list value. 71 00:05:42,250 --> 00:05:48,970 Now, if you want to copy a list value, you can import the copy module to call the copy deep copy function, 72 00:05:49,360 --> 00:05:51,960 which returns a separate copy of the list. 73 00:05:52,300 --> 00:05:54,930 It is that that has been basically passed to it. 74 00:05:55,210 --> 00:06:03,200 For example, if we go for the let's close this domino and let's go back here and we try to create C 75 00:06:03,250 --> 00:06:06,270 over that's equal to zero comma. 76 00:06:06,370 --> 00:06:09,400 One, two, three, four, five, six, seven. 77 00:06:10,480 --> 00:06:12,590 Now we say import copy. 78 00:06:13,150 --> 00:06:21,580 Then we say another variable similar to that's equal to the US copy, not the copy, and we pass the 79 00:06:21,700 --> 00:06:23,310 VAT as the variable. 80 00:06:23,740 --> 00:06:29,550 Then we see the word to add the index of one. 81 00:06:29,620 --> 00:06:32,680 We want their python to be printed. 82 00:06:33,640 --> 00:06:40,500 And now we print the value of where we get zero one, two, three, four, five, six, seven. 83 00:06:40,870 --> 00:06:43,890 But now if we were to, we get it. 84 00:06:43,920 --> 00:06:46,840 Well, we have editors that zero one. 85 00:06:46,840 --> 00:06:49,270 Then we have Biton three, four, five, six, seven. 86 00:06:49,600 --> 00:06:56,800 Now because they copied our deep copy function, was used to copy the list in the variable that is there 87 00:06:57,010 --> 00:07:03,670 to where to when an item in two is changed, the original way is unaffected. 88 00:07:04,390 --> 00:07:07,000 We would be using this later in some sections. 89 00:07:07,000 --> 00:07:10,300 When we come back to some simple substitution ciphers. 90 00:07:10,960 --> 00:07:12,350 That's it from the station. 91 00:07:12,370 --> 00:07:13,300 Thank you very much.