All language subtitles for 12. Python Variables

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,400 --> 00:00:05,320 Now in this lesson, I want to talk to you about Python variables and it's a 1 2 00:00:05,320 --> 00:00:09,220 really, really useful concept. But before we get started, 2 3 00:00:09,370 --> 00:00:14,370 first I want you to head over to the course resources and get hold of the Day 3 4 00:00:15,820 --> 00:00:20,820 1 variables start Repl.it sandbox or you can simply type the URL into the 4 5 00:00:22,330 --> 00:00:23,163 browser. 5 6 00:00:23,380 --> 00:00:28,380 I want you to first go ahead and fork this starting code so that you can work on 6 7 00:00:28,750 --> 00:00:31,990 your own version of it. Now once you've done that, 7 8 00:00:32,140 --> 00:00:37,140 then the first thing I want to do is to take a look at this line of code that 8 9 00:00:37,930 --> 00:00:41,830 you should have already. And when we run this, 9 10 00:00:41,860 --> 00:00:44,260 we should be pretty familiar with what happens, right? 10 11 00:00:44,260 --> 00:00:48,700 It will ask us for our name and when we hit enter, nothing happens. 11 12 00:00:49,060 --> 00:00:50,770 But behind the scenes, 12 13 00:00:51,160 --> 00:00:56,160 this name or this input has now been received by this function. 13 14 00:00:57,550 --> 00:01:02,020 But once that's done, it kind of just disappears, right? 14 15 00:01:02,680 --> 00:01:07,680 And there's no way for us to be able to refer to it in the future. Or is there? 15 16 00:01:10,980 --> 00:01:13,920 Well, this is where variables come in really handy. 16 17 00:01:14,520 --> 00:01:18,150 If I give the results of this action a name, 17 18 00:01:18,390 --> 00:01:20,940 well then I'll be able to refer to it later on. 18 19 00:01:21,540 --> 00:01:23,850 So at the beginning of the line, 19 20 00:01:23,940 --> 00:01:27,630 I'm going to call it name and then I'm going to add an equal sign 20 21 00:01:28,170 --> 00:01:33,170 and what this does is it assigns whatever it is that the user typed in as the 21 22 00:01:33,600 --> 00:01:38,600 input to this prompt to a variable called name. 22 23 00:01:40,350 --> 00:01:45,350 So now if I go ahead and run my code again and I enter a name, 23 24 00:01:47,970 --> 00:01:49,980 now once I hit enter, 24 25 00:01:50,040 --> 00:01:53,910 normally there's no way for me to get hold of this anymore, right? 25 26 00:01:54,480 --> 00:01:58,800 But now I can actually go ahead and write print. 26 27 00:01:59,220 --> 00:02:02,580 I'm going to print the value of this variable name. 27 28 00:02:03,300 --> 00:02:07,170 So now if I run my code and I write a name, 28 29 00:02:07,560 --> 00:02:08,393 hit enter, 29 30 00:02:08,760 --> 00:02:13,760 you'll see that this gets printed and I can use this at any point in my code 30 31 00:02:14,760 --> 00:02:19,760 just by referring to the name that's attached to this value. 31 32 00:02:21,510 --> 00:02:26,510 So it's almost like we've saved the data from this action to a name. 32 33 00:02:29,760 --> 00:02:33,660 And if you think about it, if you had a phone book, let's say, 33 34 00:02:33,660 --> 00:02:37,080 and you just jotted down the numbers of people, 34 35 00:02:37,560 --> 00:02:39,120 the next time you look at this, 35 36 00:02:39,150 --> 00:02:43,110 there's no way for you to know who's number that is, right? 36 37 00:02:43,740 --> 00:02:46,560 In a sense it's the same thing with the computer. 37 38 00:02:47,100 --> 00:02:50,160 Even though we've inputted this piece of data, 38 39 00:02:50,310 --> 00:02:55,310 there's no way for us to be able to refer to this data unless we give it a name. 39 40 00:02:56,760 --> 00:03:01,760 So in our phone book, we might say that this particular number is associated with 40 41 00:03:02,410 --> 00:03:07,410 the name James. And in programming we would call this name James a variable. 41 42 00:03:09,400 --> 00:03:14,400 So we could write something like James equals and then his phone number. 42 43 00:03:15,400 --> 00:03:19,360 And this means that in the future, if we ever need this piece of data, 43 44 00:03:19,570 --> 00:03:22,480 we can just refer to it by its name, 44 45 00:03:23,020 --> 00:03:25,900 the variable name of James. Now, 45 46 00:03:25,960 --> 00:03:28,750 as the name variable suggests, 46 47 00:03:29,470 --> 00:03:33,670 it's something that can be changed or can be varied. 47 48 00:03:34,270 --> 00:03:35,530 So for example, 48 49 00:03:35,650 --> 00:03:40,480 just because this name is set to something up here doesn't mean that I can't 49 50 00:03:40,480 --> 00:03:43,840 change it later on. So to make things simple, 50 51 00:03:43,840 --> 00:03:48,610 let's go ahead and delete the input function and let's just say name is equal to 51 52 00:03:48,610 --> 00:03:50,110 Jack. Print name. 52 53 00:03:50,320 --> 00:03:55,320 When I run that Jack is what gets printed inside the console because I'm now 53 54 00:03:55,720 --> 00:03:59,290 referring to that piece of data by the variable name. 54 55 00:04:00,100 --> 00:04:05,100 But if later on I decide to give this variable a different piece of data to hold 55 56 00:04:06,010 --> 00:04:06,843 on to, 56 57 00:04:07,000 --> 00:04:12,000 let's say Angela and I print name at this time point after I've changed it, 57 58 00:04:15,760 --> 00:04:18,850 what do you think these two lines will print? 58 59 00:04:19,450 --> 00:04:21,190 What do you think will first be printed? 59 60 00:04:21,250 --> 00:04:25,990 What do you think will be printed second? Let's hit command + enter or control + 60 61 00:04:25,990 --> 00:04:27,790 enter and see for ourselves. 61 62 00:04:28,390 --> 00:04:33,390 So even though they're both printing the same variable, at this point when we first 62 63 00:04:34,810 --> 00:04:38,080 call print, it's holding on to the value of Jack,. 63 64 00:04:38,500 --> 00:04:43,500 But by line 5 I've now changed it so that it's holding onto the value of 64 65 00:04:43,780 --> 00:04:44,613 Angela. 65 66 00:04:45,550 --> 00:04:50,550 This makes it a lot easier when we want to write code like what we did before. 66 67 00:04:51,250 --> 00:04:51,880 For example, 67 68 00:04:51,880 --> 00:04:55,750 this is the line of code that we had before and we knew that we were going to 68 69 00:04:55,750 --> 00:05:00,750 get a piece of data from this input function and then we would calculate a new 69 70 00:05:02,050 --> 00:05:04,510 piece of data using the Len function 70 71 00:05:04,990 --> 00:05:07,540 and finally we're going to print everything out. 71 72 00:05:08,320 --> 00:05:12,670 Instead of having such a long line of code, which can be quite confusing, 72 73 00:05:13,120 --> 00:05:18,100 we can, if we wanted to, use variables to store each of these steps. 73 74 00:05:18,550 --> 00:05:19,390 So for example, 74 75 00:05:19,390 --> 00:05:24,390 we could say that the name was equal to whatever the user inserted as the 75 76 00:05:25,120 --> 00:05:25,953 input 76 77 00:05:26,530 --> 00:05:30,310 and then when we wanted to calculate the length, 77 78 00:05:30,730 --> 00:05:35,680 then we could set that variable to equal the Len function. 78 79 00:05:36,070 --> 00:05:41,070 And then inside the parentheses, we'll pass in the name, the value, that's stored 79 80 00:05:41,800 --> 00:05:45,580 in the name variable right here. And finally, 80 81 00:05:45,820 --> 00:05:50,710 all that we need to do is to print the length, 81 82 00:05:53,620 --> 00:05:56,470 like so. So in this case, 82 83 00:05:56,840 --> 00:06:01,840 this data is stored under this name and then that data is what's going to be 83 84 00:06:02,360 --> 00:06:04,940 used in order to carry out this function 84 85 00:06:05,510 --> 00:06:08,780 and then the result will get stored in yet another variable 85 86 00:06:09,110 --> 00:06:11,360 and finally that variable will be printed out. 86 87 00:06:11,870 --> 00:06:16,870 So let's go ahead and run this code and type in my name. 87 88 00:06:17,090 --> 00:06:21,950 So Angela and hit enter and it does exactly the same thing, 88 89 00:06:22,460 --> 00:06:27,460 but now we've got all of these pieces of data all associated with a name that we 89 90 00:06:29,450 --> 00:06:34,160 can refer to at any later point in our code. Now it's time, 90 91 00:06:34,190 --> 00:06:36,560 you guessed it, for a code challenge. 91 92 00:06:36,860 --> 00:06:39,500 And I'm going to get you to apply what you've learned. 92 93 00:06:39,800 --> 00:06:42,860 So for all of that and more, I'll see you on the next lesson. 8974

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