Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Okay.
Now that we know how to create variables, how to initialize them, and how to use them within a string,
using the variables within our previous code should be very, very easy and I'll show you why.
First of all, I'm going to uncomment these statements because Python is ignoring them now.
And to do that, you can manually just remove the hash in front of the lines or just highlight the lines
that you want to uncomment and press control and forward slash.
Now this is done.
If you look at the code here, you can see the first part of this function is actually a string.
So it's a sequence of characters enclosed by two quotation marks.
Therefore, if we want to replace this with the value that stored in this variable, we have to do with
the same way that we did it in our print statement.
So all we have to do here is we have to close the quotation marks, the strings, and we have to append
or put our variable in the middle of the string like so.
So it's very similar to the way that we're using it in here in this print statement.
Again, we have to do it in this line.
And same for this line.
And that's it.
Now, whenever Python runs, it's going to replace interface here with the value that we initialize
it to and here.
One more thing that we need to do is use the new Mac.
So I actually modified this code in the previous lecture to show you the difference of using the variable
inside and outside the quotation marks.
So I'll just fix this here and we also need to use it in here.
And again, all we have to do is just append the code in here.
So I'm removing the Mac that's hardcoded within the string and then I'm going to append the new Mac
to the string.
So as you can see now, we're actually using the same concept that we used when we were using the variable
within the print statement.
And that's why I was saying it's very useful to get into the habit of printing your variables and using
the print function.
Also, sometimes it's a good idea if you're running system commands like this, maybe you can just print
this right here so you can just copy this and use it in a print statement and make sure that your command
is being interpreted by Python the way that you want it to look like.
So I'm going to save this and let's run our code and see what happens.
So my current Mac address ends with six, six, as you can see here.
And if we run our program, you can see it's given us a nice print statement.
And then if we do, if config line zero, you'll see the MAC address has changed to seven seven.
Now what's really handy with using the variables is let's say you want to change the Mac address of
a different interface, not for line zero.
You would have had to change the value in all of the commands in here, and if you have a bigger code
then you would have had to went and looked for every single time you use that value and change it to
the new value.
Whereas in our code, let's say I want to change the Mac address of zero, which is another interface
that I have here.
So if I do, if config 88 zero, you can see its MAC address ends with 77 actually now.
So let's change the new Mac and make it end with eight eight and run our code.
Now if we do if config 80 zero again as you can see, the MAC address changed to the new value.
So instead of going through the whole code and changing the value for line zero, all we had to do is
just change it in here and set that to ETA zero.
Same goes for changing the new Mac.
If you had a big code, you would have had to look which line of this code.
Change the Mac address instead.
If you have everything here on the top or in one place, then it's very easy for you to change it and
not to worry where this variable is used.
All you have to do is just change its value here and then it will change all over the code.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.