All language subtitles for 14. Variable Naming

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian Download
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 0 1 00:00:00,430 --> 00:00:03,310 Now when it comes to naming your variables, 1 2 00:00:03,610 --> 00:00:06,580 you can pretty much call it whatever it is you want. 2 3 00:00:07,270 --> 00:00:09,010 So instead of calling this name, 3 4 00:00:09,370 --> 00:00:14,370 I could have just called it n and I could have called this l and as long as I'm 4 5 00:00:14,920 --> 00:00:15,790 consistent. 5 6 00:00:15,880 --> 00:00:20,880 So if I wanted to get the length of N then I would have to change this as well. 6 7 00:00:21,940 --> 00:00:25,960 And if I wanted to print out L then I have to change this as well. 7 8 00:00:26,590 --> 00:00:29,260 But there's a couple of rules that you should probably follow. 8 9 00:00:29,350 --> 00:00:34,350 And the most important one is to make your code readable. Because if you come 9 10 00:00:35,800 --> 00:00:38,830 back to this in six months, 12 months, 10 11 00:00:39,280 --> 00:00:42,730 N and L is not going to have a lot of meaning for you. 11 12 00:00:43,150 --> 00:00:46,450 So try to make sure that it actually makes sense to you. 12 13 00:00:47,590 --> 00:00:48,670 And if you want to, 13 14 00:00:48,670 --> 00:00:52,630 you can actually have multiple words in the name of your variable. 14 15 00:00:52,960 --> 00:00:55,900 So for example, if you wanted to call this username, 15 16 00:00:56,260 --> 00:01:00,610 then you would write the word user and then you would separate each of the words 16 17 00:01:00,820 --> 00:01:05,680 with an underscore. But you can't have a space in between. 17 18 00:01:05,710 --> 00:01:10,030 This is not valid code and if you try to run it, you'll get a syntax error. 18 19 00:01:10,840 --> 00:01:15,840 So the name of the variable has to be one single unit and in order to separate 19 20 00:01:16,810 --> 00:01:19,300 words in Python, we use the underscore. 20 21 00:01:20,080 --> 00:01:23,500 Now if you want to use numbers in the name of your variable, 21 22 00:01:23,500 --> 00:01:25,870 you can. So for example, length1, 22 23 00:01:25,870 --> 00:01:30,870 length2. But they can't be at the beginning of the name of the variables. 23 24 00:01:31,630 --> 00:01:35,200 You can't say 1length or 3length. 24 25 00:01:35,530 --> 00:01:39,850 That will generate a syntax error as well. Finally, 25 26 00:01:40,360 --> 00:01:43,720 there's certain privileged words that we use, for example, 26 27 00:01:43,720 --> 00:01:47,560 the names of our functions like print and input. 27 28 00:01:48,040 --> 00:01:53,040 And it's usually good practice to not use them as the names of your variables 28 29 00:01:53,530 --> 00:01:57,430 because you can see that syntax highlighting gets messed up because it thinks 29 30 00:01:57,670 --> 00:02:00,130 that is actually input function you're trying to create. 30 31 00:02:00,460 --> 00:02:04,330 And even though often when you run your app, it might not have any issues, 31 32 00:02:04,540 --> 00:02:07,600 this is really bad practice because it's very confusing. 32 33 00:02:08,680 --> 00:02:12,430 So try to make sure that all the names of your variables get highlighted, 33 34 00:02:12,670 --> 00:02:15,760 like the other variables in the same color. Now, 34 35 00:02:15,790 --> 00:02:20,170 the final thing to remember is that if you decide to call your variable this 35 36 00:02:20,170 --> 00:02:25,170 particular name, n-a-m-e, and at a later point you make a typo and you spell it 36 37 00:02:26,380 --> 00:02:31,090 wrong, so maybe instead of name you said nama, 37 38 00:02:31,780 --> 00:02:36,640 this is not going to work and when you run your code you'll get what's called a 38 39 00:02:36,670 --> 00:02:41,670 name error because it says this name is not defined. And the idea is that you 39 40 00:02:43,390 --> 00:02:48,390 would look at where the error is, line 2, print nama and you'll see, 40 41 00:02:49,090 --> 00:02:51,880 Oh that's not right. It's meant to be spelled n-a- 41 42 00:02:52,090 --> 00:02:57,090 m-e. So you'll have to go and fix it in order for your code to work. 42 43 00:02:58,000 --> 00:03:02,800 Now remember that this is not because Python is doing any sort of spell-checking 43 44 00:03:02,800 --> 00:03:06,730 for you. It's like, Oh, that's not how you spell name. No. In fact, 44 45 00:03:06,850 --> 00:03:11,850 if you decided to call this nama and you, later on, used it as name, 45 46 00:03:13,090 --> 00:03:16,000 there's no problems, there's no issues, no errors,. 46 47 00:03:16,690 --> 00:03:18,670 As long as it's consistent, 47 48 00:03:19,060 --> 00:03:23,830 this is the name that's associated with this piece of data. Later on, 48 49 00:03:23,830 --> 00:03:28,780 when you want to use this piece of data, you use this name to refer to it. 49 50 00:03:29,180 --> 00:03:32,290 And as long as these two spellings are identical, 50 51 00:03:32,500 --> 00:03:34,660 then the computer doesn't care at all. 51 52 00:03:35,230 --> 00:03:38,290 So when you get a name error in your code, 52 53 00:03:38,350 --> 00:03:43,350 you now know it's probably because you've misspelled or mistyped one of the 53 54 00:03:43,570 --> 00:03:47,950 variable names somewhere in your code. Now in the next lesson, 54 55 00:03:48,040 --> 00:03:52,510 I prepared a quiz for you where you'll get to select which variable names are 55 56 00:03:52,540 --> 00:03:55,390 valid and which ones are not good practice. 56 57 00:03:55,720 --> 00:03:58,060 Have a go at that over on the next lesson. 5770

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.