Afrikaans
Akan
Albanian
Amharic
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
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
Welcome back. So, so far we've talked a little expressions,
which are the building blocks of programs, values,
which are what Python evaluates in expression two and then types in.
In Python, every value has a type.
So, there is one more concept which is called a statement.
A Statement is a complete instruction that the Python program executes.
So, the only statement that we have seen so
far has been the assignment statement or that's when
we say something like X equals one plus two plus three.
So, here this is a complete statement.
In this case, it's an assignment statement.
But, this part is an expression.
So, when Python is competing the value of this expression,
it breaks it down in the smaller parts,
so it first adds one plus two,
takes the result and then add three to that and
then it get six as the value of this expression.
Then the statement says assign the value six into the value equal to x.
Now, let's look at just a few other examples of expressions.
So here, the expression 500 is what's called the literal expression
because the value 500 is going to be the same as the expression itself,
and this has type integer,
another literal expression with a float might be 3.14,
which has value 3.14 and has type float.
Again, we can have slightly more complex expressions as well.
So, we might have an expression that adds two numbers,
so 200 plus 300 is an expression.
When Python sees this expression,
it competes its value which is 500 and an integer.
We have expressions of course with floats as well.
So, we can have 10.0 plus 5.0 an expression that has a value 15.0,
which is a float.
Now, whenever we call a function including the print function,
Python first evaluates the value of the expression that we are actually printing.
So here, on line one,
we are calling the print function.
And Python sees that the argument to the print function is this expression.
So, what Python does is it doesn't printout the expression
itself instead first competes the value of this expression.
It computes the value of this expression by
breaking it down in the smaller sub-expressions.
So here, Python is going to compute one plus one and get two.
Then it's going to compute the value of
this subexpression two times three and it gets six,
and then we add two plus six to get eight.
Eight is the final value that we actually printout.
Here, when we printout the value of this expression,
then Python first figures out what's the value of this expression,
here it's a literal expression,
so Python figures out it's a string that has H-E-L-L-O as its characters,
and then when we call the len function on that string,
then we see that there are one,
two, three, four, five characters,
so the value of this overall expression is going to be five,
and that's what gets printed out.
So again, Python does the work of
computing the value of the expression that we're printing out,
and it prints out the value of the expression,
and not the expression itself.
So, you'll see when we are on our code that the first line prints out eight,
because that's the value of this expression,
the second line prints out five,
because that's the value of this expression.
The same thing goes when we're actually assigning variable values.
So, if we say Y equals 3.14,
then that assigns the variable Y to the value,
the float 3.14, but when we say X equals the len of "hello,"
then as Python is evaluating line two,
it crosses this out,
and computes the value of the actual expression,
so the value of that expression is five,
and so, that value five gets assigned to X.
So in our variables values diagram,
X points to five.
Now, when we print out X,
we're going to print out five,
when we print out Y, we're going to print out 3.14.
Now, we can combine different kinds of expressions into larger expressions as well.
So here, this print statement prints out the value of one large expression,
this expression combines literal expressions with function call expressions,
and also arithmetic operators.
Now, when Python is competing the value of this more complicated expression,
then again, it breaks down every expression.
So here Python goes from the inside out,
and it says, "Okay.
What's the len of Hello?"
And it crosses this out,
and replaces it with five.
What's the len of goodbye?
We get one, two,
three, four, five, six,
seven, so it crosses this out,
and it gets seven,
and then it knows we're printing out the value of two times five plus seven,
so two times five plus seven,
then Python computes the value of this subexpression,
two times five, and it gets 10,
and it adds seven to that,
and then it gets 17 as the value of the overall expression.
So, if I run this code,
it's just going to print out 17.
So, in this code, we first assign X to B2,
so in our variables values table,
we say that X points to two,
then we assign Y to be B1,
so we assign Y to be one.
Now, again, when Python sees a complex expression like square when called with Y plus 3,
it evaluates from the inside out.
So, it first figures out what's the value of Y,
and then it sees that Y is one,
and then we add one plus three,
and that gives us four,
and so that means that we're taking the square of four,
and that gives us 16,
and that means that the value of this overall expression is
going to be 16.
Here on line four,
we're printing out square of Y plus square of X,
so Python again, you can think of it as competing from the inside out,
so Python is going to replace X with two,
so that means that square of two,
the value of this expression is going to be four,
when we add Y,
whose value is one to four,
then we get five,
so that's you're taking the square of one plus four,
or the square of five,
and then when we take the square of five,
then the value of this overall expression is going to be 25.
In this third example,
we're taking sub square of Y,
and square of X, so Python first asks what's the value of Y,
for Y it gets one,
and then square of one, is going to be one,
and that's whats the value of X,
that's two, it takes square of two, to get four,
and then so we're calling sub with one as the first argument,
and four as the second argument,
and that's going to give us one minus four, or negative three.
So, you'll see that's what gets printed out for this line,
and 25 gets printed out here,
and 16 gets printed out for line three.
That's all for now. Until next time.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.