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
English
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
Persian
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 (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
1
Hi, in this lecture you're going to learn
about variables. So what is a variable?
3
Well a variable is like a container
where you can store various data types
5
in Python for instance this program now
this doesn't have any variable in it for
7
now, so let me try and execute it and
you'll see that this prints out of the
9
hello string. String is a data type, but
we'll cover that later. Now what is the
11
variable? Well and variables will keep
your code more organized. Let me create a
13
variable here, greeting so you can call
your variables whatever you like you can
15
give them any name however there are
some naming rules which I'll mention in
17
just a bit, so let me create this
variable for now. I'll store in this
19
variable, I said variables are like
containers so I'll store this text in the
21
variable greeting and then what I do is
instead of doing print hello I'll do
23
print greeting and save the script ctrl
s and then go through the command line,
25
the upper arrow key, enter to execute and
you get the same output. So this is how
27
you create a variable you don't use any
quotes because when you use quotes you
29
are creating a string data type not a
variable and you can also use a dash
31
before the variable that would also be
fine so you get the output correctly
33
but you cannot use numbers before the
variable ctrl s to save, execute and get
35
an invalid syntax, so this syntax is not
valid in Python, but you can use numbers
37
after or between the variable name let's
say here greeting2. So that would
39
be fine to use so that's the condition
about naming
41
your variables, you can start them with a
letter or a, or an underscore. Now if
43
you're not experienced with programming
you may still be confused on why do we
45
use these variables? Well this is a very
simple program, actually very useless, but
47
normally your programs will interact
with your users. That is what we call a
49
real program. You create a program to
give it to people so they can interact
51
with the program they can generate all
different outputs and so on, so let's go
53
Ahead and make this program more dynamic, so
what I'll do here is I'll get the text
55
from the user interactively. To do that
you need to use the input function, this
57
is also a Python function and inside
the function you can enter a message to the
59
user so let's say write a greeting.
A column and make some space there and then
61
you print greeting2, save the script.
Execute and now the program is asking
63
us to enter some input so let's go ahead
and say hi this time and we get the output
65
Printed out in here, hi, so what
happened here is we created a variable
67
and that variable will store the value
that the user submits in the command line
69
here, in the terminal so the user
submitted the hi text and this text will be
71
stored in this variable so as I said
variables are like containers and then can
73
use this text in various ways, but in
this scenario I'm just passing it to the
75
print function, so I want to print it out
on the terminal here and the print
77
function will get the value that is
stored in the greeting2 variable and
79
print it out on the terminal. That's it.
And yeah, I'd like to close this lecture
81
now and I'll see you in the next lecture.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.