Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,440 --> 00:00:01,890
Okay.
2
00:00:01,890 --> 00:00:11,070
So now we have a script that can change the Mac address of 102001122334466.
3
00:00:12,090 --> 00:00:18,240
Now, as you can see, this is not a great script because all we can use it for is to change the Mac
4
00:00:18,240 --> 00:00:21,990
address of LAN zero to this specific Mac address.
5
00:00:23,100 --> 00:00:29,880
So we can't use it to change the Mac address of any other interface, and we can't change it to any
6
00:00:29,880 --> 00:00:36,060
other Mac address other than this one unless you come in and manually change the code here, which is
7
00:00:36,060 --> 00:00:37,440
not a good practice.
8
00:00:38,370 --> 00:00:45,180
So a better implementation would be to use variables for the places that vary.
9
00:00:45,450 --> 00:00:47,160
So we have the line zero.
10
00:00:47,160 --> 00:00:48,600
Here is a variable.
11
00:00:48,600 --> 00:00:54,470
The value of it can change depending on the interface that the person wants to use.
12
00:00:54,480 --> 00:00:58,680
So if you want to change the Mac address of to zero, you can set it to zero.
13
00:00:58,680 --> 00:01:01,080
If you want to change the MAC address of line one.
14
00:01:01,080 --> 00:01:05,010
If you have two wireless interfaces, then you can change for line one.
15
00:01:05,760 --> 00:01:11,850
Therefore, this value right here is a variable and it's better to use a variable for that.
16
00:01:12,630 --> 00:01:14,880
Same goes for the Mac address here.
17
00:01:15,300 --> 00:01:21,600
As described before, if you're actually using this in real life, you'd want to be always using a different
18
00:01:21,600 --> 00:01:26,370
Mac address, and you won't always want to use the same Mac address over and over.
19
00:01:27,300 --> 00:01:33,180
Therefore, it will make sense to use a variable for the value of the Mac address in here as well.
20
00:01:33,750 --> 00:01:41,460
And what I mean by a variable is a value that can be easily changed through the user input or through
21
00:01:41,460 --> 00:01:42,840
the program itself.
22
00:01:43,870 --> 00:01:51,010
Now variables are used everywhere in programming, in all programming languages, not only in Python,
23
00:01:51,310 --> 00:01:52,900
and they are very useful.
24
00:01:52,900 --> 00:01:55,510
You can't really write a program without a variable.
25
00:01:56,620 --> 00:02:03,880
So technically speaking, a variable is a location in memory that contains a certain value.
26
00:02:04,180 --> 00:02:12,880
But what we actually mean by that is it's a word or a name that stores a value, something very similar
27
00:02:12,880 --> 00:02:15,070
to when we use X and Y in maths.
28
00:02:15,070 --> 00:02:21,250
We always used variables and we always got questions in exams to find X and solve equations and all
29
00:02:21,250 --> 00:02:21,730
that.
30
00:02:21,730 --> 00:02:25,300
And all the letters in these equations are variables.
31
00:02:25,630 --> 00:02:33,130
So you can think of a variable as a box that contains a certain value or as a container that contains
32
00:02:33,130 --> 00:02:34,300
a certain value.
33
00:02:35,320 --> 00:02:43,000
Now, a very simple example that I have here is we can just do in Python set x equals one, then x will
34
00:02:43,000 --> 00:02:44,740
hold the value of one.
35
00:02:44,980 --> 00:02:51,190
So you can say y is equal to x plus x, that means y is equal to one plus one.
36
00:02:51,190 --> 00:02:53,860
Then Y is going to have a value of two.
37
00:02:53,860 --> 00:02:57,670
And then you can print Y and you'll see two on screen.
38
00:02:58,330 --> 00:03:04,300
Now this is very simple and not useful, and that's why programming can be boring if you don't have
39
00:03:04,300 --> 00:03:04,990
a purpose.
40
00:03:04,990 --> 00:03:06,870
So we're not going to be doing this.
41
00:03:06,880 --> 00:03:12,550
What we are going to do is adopt this in our cool script in here.
42
00:03:12,730 --> 00:03:19,210
So we want line zero to be a variable and we want the Mac to be a variable.
43
00:03:19,720 --> 00:03:25,750
So all we have to do is before we use these variables, type them in here.
44
00:03:25,750 --> 00:03:28,510
So we're going to create our first variable.
45
00:03:28,510 --> 00:03:32,470
And to create that, all you have to do is just type its name.
46
00:03:32,500 --> 00:03:37,630
Now in maths, we're used to use X and Y when we're using variables.
47
00:03:37,630 --> 00:03:40,930
You can do that with Python, but it's not a good practice.
48
00:03:40,930 --> 00:03:44,590
It's better to name your variables meaningful names.
49
00:03:44,590 --> 00:03:49,540
So names that are relevant to the value that stored in that variable.
50
00:03:50,050 --> 00:03:57,250
You can use letters and numbers and variables, but it has to start with a letter or an underscore.
51
00:03:57,490 --> 00:04:03,610
You can use the underscore anywhere within the variable name, and the names are case sensitive.
52
00:04:03,970 --> 00:04:11,470
So since we want to use meaningful names, a very good variable name would be interface.
53
00:04:12,190 --> 00:04:14,680
To hold the value for the interface.
54
00:04:15,310 --> 00:04:17,779
Now our interface is line zero.
55
00:04:17,800 --> 00:04:20,920
So we're going to initialize that to line zero.
56
00:04:22,019 --> 00:04:29,040
Now we have a variable or a box named interface and it has a value of zero.
57
00:04:29,160 --> 00:04:37,020
So everywhere we use line zero, we can just substitute interface and Python as it interprets the code.
58
00:04:37,020 --> 00:04:44,010
It will replace any occurrence of interface with the value that we set it to, which is line zero.
59
00:04:44,400 --> 00:04:50,790
Now before I use that in the code here, because this is something new, I'm going to use it in a print
60
00:04:50,790 --> 00:04:51,600
statement.
61
00:04:51,630 --> 00:04:58,170
It's actually a really good idea as you go along with coding to print stuff as your programming so you
62
00:04:58,170 --> 00:05:03,660
can see what's the value for that variable at this line or at this moment of time.
63
00:05:03,750 --> 00:05:10,560
So it's a good practice and it will actually make you understand the idea of variables more and you'll
64
00:05:10,560 --> 00:05:12,060
get more comfortable with it.
65
00:05:12,750 --> 00:05:19,470
So first of all, I'm just going to comment all of this basically commenting a line means that we're
66
00:05:19,470 --> 00:05:24,180
telling Python to ignore this line and don't treat it as code.
67
00:05:24,630 --> 00:05:31,530
To do that, all we have to do is just put the hash symbol before the line or you can press control
68
00:05:31,710 --> 00:05:37,500
and forward slash and that will automatically add comments to multiple lines.
69
00:05:38,360 --> 00:05:42,710
So whenever we run this code, all of this will be ignored.
70
00:05:43,010 --> 00:05:47,480
And what I want to do in here, I actually want to use a very simple print statement.
71
00:05:48,800 --> 00:05:55,580
And inside it, we're just going to give a notification to the user and we're just going to say change
72
00:05:55,670 --> 00:05:57,620
in Mac address for.
73
00:05:58,920 --> 00:06:03,780
And then I want to say the name of the interface that the script will work on.
74
00:06:04,110 --> 00:06:08,160
So we have to use the interface variable in here.
75
00:06:08,520 --> 00:06:14,130
And to do that, all we have to do is append this variable to the string.
76
00:06:14,220 --> 00:06:20,940
So like we said before, any sequence of characters enclosed between two quotations is treated as a
77
00:06:20,940 --> 00:06:23,430
string or is called a string in Python.
78
00:06:23,970 --> 00:06:29,340
Now, since our variable is a string as well, as you can see, it's a sequence of characters as well.
79
00:06:29,460 --> 00:06:36,090
So all we have to do in Python is just put a plus followed by the the variable name, which is interface.
80
00:06:38,030 --> 00:06:38,640
And that's it.
81
00:06:38,660 --> 00:06:41,380
Now, when we interpret this, let's go down and do it.
82
00:06:41,390 --> 00:06:48,710
So if we just do Python Mac change or dot p, you'll see it's going to print for me changing mac address
83
00:06:48,710 --> 00:06:57,650
for and instead of interface here it replaced it with the value that we have here, which is line zero.
84
00:06:58,370 --> 00:07:05,540
Now this is cool, but if you look at our code here and remember what we said, we also want to use
85
00:07:05,540 --> 00:07:08,270
a variable for the Mac address value.
86
00:07:08,690 --> 00:07:09,860
So let's do that.
87
00:07:09,860 --> 00:07:12,260
Let's call this variable now new Mac.
88
00:07:14,110 --> 00:07:24,670
And let's set that to 001122, three, three, four, four, and we'll set it to seven seven this time.
89
00:07:25,180 --> 00:07:27,040
So it's different than the last time.
90
00:07:27,610 --> 00:07:33,370
Now, again, simply by doing this, we created a new variable or a new box or a new container that's
91
00:07:33,370 --> 00:07:34,450
called new mark.
92
00:07:34,750 --> 00:07:39,790
And its value is a sequence of characters enclosed between two quotations.
93
00:07:39,790 --> 00:07:41,290
So it's a string.
94
00:07:41,950 --> 00:07:45,280
Now let's append that to our string in here.
95
00:07:45,280 --> 00:07:47,350
So we have the string in the print statement.
96
00:07:47,350 --> 00:07:50,770
And I want to say changing Mac address for interface.
97
00:07:50,770 --> 00:07:56,740
So four lines zero two and then put the value of the Mac, which we're going to change the current MAC
98
00:07:56,740 --> 00:07:57,760
address to.
99
00:07:58,150 --> 00:08:03,610
So again, just to append the string, all we have to do is just put a plus followed by the rest of
100
00:08:03,610 --> 00:08:08,740
this string, which is we're saying change in Mac address for Interface two.
101
00:08:09,310 --> 00:08:13,600
And then we want to put the value of the of the new Mac address.
102
00:08:13,750 --> 00:08:20,590
Again, all we have to do is put a plus followed by the new Mac, and that's it.
103
00:08:20,890 --> 00:08:28,390
So all we're saying is change your Mac address for we close the quotation and then we put our variable,
104
00:08:28,420 --> 00:08:34,659
because if we put the variable inside the quotation, python will think this is part of the string and
105
00:08:34,659 --> 00:08:36,940
it will just print it as interface.
106
00:08:36,960 --> 00:08:40,059
It won't substitute its value with line zero.
107
00:08:40,720 --> 00:08:43,659
Same goes with using the new Mac in here.
108
00:08:43,659 --> 00:08:50,890
If you put that inside the quotation, it will just treat that as a string and it won't print its value.
109
00:08:51,460 --> 00:08:54,790
So now if we go down and just run our code again.
110
00:08:56,010 --> 00:09:03,120
As you can see, it's printing changing mac address for line zero so substituted the value of interface
111
00:09:03,120 --> 00:09:09,090
with line zero with the value that we initialize the two and it's changing it to the new Mac.
112
00:09:09,090 --> 00:09:13,500
Again, it's substituting the new Mac variable with this.
113
00:09:14,220 --> 00:09:19,590
Now just as a quick test, I know I spend a bit too much time on this, but just as a quick test, if
114
00:09:19,590 --> 00:09:24,660
I put the new Mac here inside the string and run this.
115
00:09:25,640 --> 00:09:30,230
You'll see that the interface will be substituted with the value of line zero.
116
00:09:30,380 --> 00:09:33,740
But Python will not know that new Mac is a variable.
117
00:09:33,770 --> 00:09:40,070
It will just print it as part of the string because we put it inside the quotation mark.
118
00:09:41,830 --> 00:09:42,940
So that's it for now.
119
00:09:42,940 --> 00:09:45,730
Just a quick introduction to variables.
120
00:09:45,730 --> 00:09:51,460
I wanted to show you how to use it in a print statement and get into the habit of printing the value
121
00:09:51,460 --> 00:09:52,330
of variables.
122
00:09:52,330 --> 00:09:57,430
Because when you have longer code, it might be a smart idea to print it as you're writing the code
123
00:09:57,430 --> 00:10:00,820
to make sure that its value is still what you want it to be.
124
00:10:01,390 --> 00:10:07,630
And the next lecture will use the variables that we just created in the code so that we can change the
125
00:10:07,630 --> 00:10:11,530
Mac address and the interface quickly using these variables.
13132
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.