Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,030 --> 00:00:01,620
Okay.
2
00:00:01,630 --> 00:00:08,109
Now that we know how to create variables, how to initialize them, and how to use them within a string,
3
00:00:08,260 --> 00:00:14,170
using the variables within our previous code should be very, very easy and I'll show you why.
4
00:00:14,770 --> 00:00:20,230
First of all, I'm going to uncomment these statements because Python is ignoring them now.
5
00:00:20,230 --> 00:00:26,350
And to do that, you can manually just remove the hash in front of the lines or just highlight the lines
6
00:00:26,350 --> 00:00:30,190
that you want to uncomment and press control and forward slash.
7
00:00:31,210 --> 00:00:32,439
Now this is done.
8
00:00:33,310 --> 00:00:40,030
If you look at the code here, you can see the first part of this function is actually a string.
9
00:00:40,030 --> 00:00:44,350
So it's a sequence of characters enclosed by two quotation marks.
10
00:00:44,800 --> 00:00:51,280
Therefore, if we want to replace this with the value that stored in this variable, we have to do with
11
00:00:51,280 --> 00:00:54,430
the same way that we did it in our print statement.
12
00:00:55,060 --> 00:01:02,890
So all we have to do here is we have to close the quotation marks, the strings, and we have to append
13
00:01:02,890 --> 00:01:06,610
or put our variable in the middle of the string like so.
14
00:01:07,540 --> 00:01:11,890
So it's very similar to the way that we're using it in here in this print statement.
15
00:01:12,700 --> 00:01:14,590
Again, we have to do it in this line.
16
00:01:20,390 --> 00:01:22,130
And same for this line.
17
00:01:28,190 --> 00:01:28,800
And that's it.
18
00:01:28,820 --> 00:01:34,790
Now, whenever Python runs, it's going to replace interface here with the value that we initialize
19
00:01:34,790 --> 00:01:36,260
it to and here.
20
00:01:37,040 --> 00:01:40,520
One more thing that we need to do is use the new Mac.
21
00:01:40,820 --> 00:01:46,220
So I actually modified this code in the previous lecture to show you the difference of using the variable
22
00:01:46,220 --> 00:01:48,560
inside and outside the quotation marks.
23
00:01:48,680 --> 00:01:54,500
So I'll just fix this here and we also need to use it in here.
24
00:01:54,500 --> 00:01:58,580
And again, all we have to do is just append the code in here.
25
00:01:58,580 --> 00:02:06,140
So I'm removing the Mac that's hardcoded within the string and then I'm going to append the new Mac
26
00:02:06,170 --> 00:02:07,400
to the string.
27
00:02:08,910 --> 00:02:15,300
So as you can see now, we're actually using the same concept that we used when we were using the variable
28
00:02:15,300 --> 00:02:17,040
within the print statement.
29
00:02:17,280 --> 00:02:24,270
And that's why I was saying it's very useful to get into the habit of printing your variables and using
30
00:02:24,270 --> 00:02:25,320
the print function.
31
00:02:26,130 --> 00:02:32,550
Also, sometimes it's a good idea if you're running system commands like this, maybe you can just print
32
00:02:32,550 --> 00:02:38,460
this right here so you can just copy this and use it in a print statement and make sure that your command
33
00:02:38,490 --> 00:02:42,840
is being interpreted by Python the way that you want it to look like.
34
00:02:43,680 --> 00:02:49,050
So I'm going to save this and let's run our code and see what happens.
35
00:02:50,090 --> 00:02:54,350
So my current Mac address ends with six, six, as you can see here.
36
00:02:54,710 --> 00:02:59,990
And if we run our program, you can see it's given us a nice print statement.
37
00:03:00,200 --> 00:03:08,330
And then if we do, if config line zero, you'll see the MAC address has changed to seven seven.
38
00:03:08,930 --> 00:03:15,320
Now what's really handy with using the variables is let's say you want to change the Mac address of
39
00:03:15,320 --> 00:03:17,540
a different interface, not for line zero.
40
00:03:17,630 --> 00:03:23,690
You would have had to change the value in all of the commands in here, and if you have a bigger code
41
00:03:23,690 --> 00:03:29,180
then you would have had to went and looked for every single time you use that value and change it to
42
00:03:29,180 --> 00:03:30,200
the new value.
43
00:03:30,680 --> 00:03:37,940
Whereas in our code, let's say I want to change the Mac address of zero, which is another interface
44
00:03:37,940 --> 00:03:38,930
that I have here.
45
00:03:38,930 --> 00:03:46,420
So if I do, if config 88 zero, you can see its MAC address ends with 77 actually now.
46
00:03:46,430 --> 00:03:53,510
So let's change the new Mac and make it end with eight eight and run our code.
47
00:03:54,990 --> 00:04:02,910
Now if we do if config 80 zero again as you can see, the MAC address changed to the new value.
48
00:04:03,480 --> 00:04:09,120
So instead of going through the whole code and changing the value for line zero, all we had to do is
49
00:04:09,120 --> 00:04:12,570
just change it in here and set that to ETA zero.
50
00:04:13,230 --> 00:04:15,550
Same goes for changing the new Mac.
51
00:04:15,570 --> 00:04:19,800
If you had a big code, you would have had to look which line of this code.
52
00:04:19,800 --> 00:04:22,140
Change the Mac address instead.
53
00:04:22,140 --> 00:04:27,510
If you have everything here on the top or in one place, then it's very easy for you to change it and
54
00:04:27,510 --> 00:04:29,880
not to worry where this variable is used.
55
00:04:29,880 --> 00:04:35,010
All you have to do is just change its value here and then it will change all over the code.
5864
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.