Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:03,710 --> 00:00:09,195
Welcome back. So, so far we've talked a little expressions,
2
00:00:09,195 --> 00:00:13,260
which are the building blocks of programs, values,
3
00:00:13,260 --> 00:00:18,240
which are what Python evaluates in expression two and then types in.
4
00:00:18,240 --> 00:00:20,970
In Python, every value has a type.
5
00:00:20,970 --> 00:00:24,375
So, there is one more concept which is called a statement.
6
00:00:24,375 --> 00:00:29,280
A Statement is a complete instruction that the Python program executes.
7
00:00:29,280 --> 00:00:31,800
So, the only statement that we have seen so
8
00:00:31,800 --> 00:00:34,200
far has been the assignment statement or that's when
9
00:00:34,200 --> 00:00:39,285
we say something like X equals one plus two plus three.
10
00:00:39,285 --> 00:00:43,570
So, here this is a complete statement.
11
00:00:44,270 --> 00:00:47,565
In this case, it's an assignment statement.
12
00:00:47,565 --> 00:00:52,960
But, this part is an expression.
13
00:00:55,670 --> 00:00:59,265
So, when Python is competing the value of this expression,
14
00:00:59,265 --> 00:01:01,125
it breaks it down in the smaller parts,
15
00:01:01,125 --> 00:01:02,970
so it first adds one plus two,
16
00:01:02,970 --> 00:01:05,460
takes the result and then add three to that and
17
00:01:05,460 --> 00:01:08,670
then it get six as the value of this expression.
18
00:01:08,670 --> 00:01:15,285
Then the statement says assign the value six into the value equal to x.
19
00:01:15,285 --> 00:01:19,155
Now, let's look at just a few other examples of expressions.
20
00:01:19,155 --> 00:01:23,984
So here, the expression 500 is what's called the literal expression
21
00:01:23,984 --> 00:01:29,205
because the value 500 is going to be the same as the expression itself,
22
00:01:29,205 --> 00:01:31,560
and this has type integer,
23
00:01:31,560 --> 00:01:35,535
another literal expression with a float might be 3.14,
24
00:01:35,535 --> 00:01:39,375
which has value 3.14 and has type float.
25
00:01:39,375 --> 00:01:43,485
Again, we can have slightly more complex expressions as well.
26
00:01:43,485 --> 00:01:46,620
So, we might have an expression that adds two numbers,
27
00:01:46,620 --> 00:01:49,740
so 200 plus 300 is an expression.
28
00:01:49,740 --> 00:01:51,870
When Python sees this expression,
29
00:01:51,870 --> 00:01:55,470
it competes its value which is 500 and an integer.
30
00:01:55,470 --> 00:01:58,635
We have expressions of course with floats as well.
31
00:01:58,635 --> 00:02:04,995
So, we can have 10.0 plus 5.0 an expression that has a value 15.0,
32
00:02:04,995 --> 00:02:07,035
which is a float.
33
00:02:07,035 --> 00:02:11,100
Now, whenever we call a function including the print function,
34
00:02:11,100 --> 00:02:16,065
Python first evaluates the value of the expression that we are actually printing.
35
00:02:16,065 --> 00:02:18,300
So here, on line one,
36
00:02:18,300 --> 00:02:20,010
we are calling the print function.
37
00:02:20,010 --> 00:02:25,020
And Python sees that the argument to the print function is this expression.
38
00:02:25,020 --> 00:02:28,410
So, what Python does is it doesn't printout the expression
39
00:02:28,410 --> 00:02:32,115
itself instead first competes the value of this expression.
40
00:02:32,115 --> 00:02:34,680
It computes the value of this expression by
41
00:02:34,680 --> 00:02:37,320
breaking it down in the smaller sub-expressions.
42
00:02:37,320 --> 00:02:42,075
So here, Python is going to compute one plus one and get two.
43
00:02:42,075 --> 00:02:44,820
Then it's going to compute the value of
44
00:02:44,820 --> 00:02:48,180
this subexpression two times three and it gets six,
45
00:02:48,180 --> 00:02:52,170
and then we add two plus six to get eight.
46
00:02:52,170 --> 00:02:56,190
Eight is the final value that we actually printout.
47
00:02:56,190 --> 00:03:00,620
Here, when we printout the value of this expression,
48
00:03:00,620 --> 00:03:04,340
then Python first figures out what's the value of this expression,
49
00:03:04,340 --> 00:03:05,825
here it's a literal expression,
50
00:03:05,825 --> 00:03:11,505
so Python figures out it's a string that has H-E-L-L-O as its characters,
51
00:03:11,505 --> 00:03:14,830
and then when we call the len function on that string,
52
00:03:14,830 --> 00:03:16,930
then we see that there are one,
53
00:03:16,930 --> 00:03:19,720
two, three, four, five characters,
54
00:03:19,720 --> 00:03:23,510
so the value of this overall expression is going to be five,
55
00:03:23,510 --> 00:03:25,125
and that's what gets printed out.
56
00:03:25,125 --> 00:03:27,250
So again, Python does the work of
57
00:03:27,250 --> 00:03:30,100
computing the value of the expression that we're printing out,
58
00:03:30,100 --> 00:03:32,290
and it prints out the value of the expression,
59
00:03:32,290 --> 00:03:34,090
and not the expression itself.
60
00:03:34,090 --> 00:03:38,175
So, you'll see when we are on our code that the first line prints out eight,
61
00:03:38,175 --> 00:03:39,975
because that's the value of this expression,
62
00:03:39,975 --> 00:03:41,475
the second line prints out five,
63
00:03:41,475 --> 00:03:44,385
because that's the value of this expression.
64
00:03:44,385 --> 00:03:48,850
The same thing goes when we're actually assigning variable values.
65
00:03:48,850 --> 00:03:52,820
So, if we say Y equals 3.14,
66
00:03:53,390 --> 00:03:58,510
then that assigns the variable Y to the value,
67
00:03:59,030 --> 00:04:06,765
the float 3.14, but when we say X equals the len of "hello,"
68
00:04:06,765 --> 00:04:10,005
then as Python is evaluating line two,
69
00:04:10,005 --> 00:04:11,655
it crosses this out,
70
00:04:11,655 --> 00:04:14,450
and computes the value of the actual expression,
71
00:04:14,450 --> 00:04:17,335
so the value of that expression is five,
72
00:04:17,335 --> 00:04:21,945
and so, that value five gets assigned to X.
73
00:04:21,945 --> 00:04:24,105
So in our variables values diagram,
74
00:04:24,105 --> 00:04:25,590
X points to five.
75
00:04:25,590 --> 00:04:27,375
Now, when we print out X,
76
00:04:27,375 --> 00:04:28,815
we're going to print out five,
77
00:04:28,815 --> 00:04:32,820
when we print out Y, we're going to print out 3.14.
78
00:04:32,820 --> 00:04:38,315
Now, we can combine different kinds of expressions into larger expressions as well.
79
00:04:38,315 --> 00:04:44,720
So here, this print statement prints out the value of one large expression,
80
00:04:44,720 --> 00:04:53,890
this expression combines literal expressions with function call expressions,
81
00:04:58,130 --> 00:05:02,260
and also arithmetic operators.
82
00:05:03,590 --> 00:05:08,814
Now, when Python is competing the value of this more complicated expression,
83
00:05:08,814 --> 00:05:12,175
then again, it breaks down every expression.
84
00:05:12,175 --> 00:05:15,865
So here Python goes from the inside out,
85
00:05:15,865 --> 00:05:17,020
and it says, "Okay.
86
00:05:17,020 --> 00:05:18,575
What's the len of Hello?"
87
00:05:18,575 --> 00:05:20,040
And it crosses this out,
88
00:05:20,040 --> 00:05:21,660
and replaces it with five.
89
00:05:21,660 --> 00:05:22,995
What's the len of goodbye?
90
00:05:22,995 --> 00:05:24,240
We get one, two,
91
00:05:24,240 --> 00:05:26,100
three, four, five, six,
92
00:05:26,100 --> 00:05:28,545
seven, so it crosses this out,
93
00:05:28,545 --> 00:05:30,155
and it gets seven,
94
00:05:30,155 --> 00:05:34,195
and then it knows we're printing out the value of two times five plus seven,
95
00:05:34,195 --> 00:05:39,825
so two times five plus seven,
96
00:05:39,825 --> 00:05:42,865
then Python computes the value of this subexpression,
97
00:05:42,865 --> 00:05:45,250
two times five, and it gets 10,
98
00:05:45,250 --> 00:05:48,350
and it adds seven to that,
99
00:05:48,420 --> 00:05:54,980
and then it gets 17 as the value of the overall expression.
100
00:05:54,980 --> 00:05:56,735
So, if I run this code,
101
00:05:56,735 --> 00:05:59,570
it's just going to print out 17.
102
00:05:59,570 --> 00:06:03,785
So, in this code, we first assign X to B2,
103
00:06:03,785 --> 00:06:07,930
so in our variables values table,
104
00:06:07,930 --> 00:06:10,855
we say that X points to two,
105
00:06:10,855 --> 00:06:13,080
then we assign Y to be B1,
106
00:06:13,080 --> 00:06:15,705
so we assign Y to be one.
107
00:06:15,705 --> 00:06:21,960
Now, again, when Python sees a complex expression like square when called with Y plus 3,
108
00:06:21,960 --> 00:06:24,525
it evaluates from the inside out.
109
00:06:24,525 --> 00:06:27,905
So, it first figures out what's the value of Y,
110
00:06:27,905 --> 00:06:30,575
and then it sees that Y is one,
111
00:06:30,575 --> 00:06:34,150
and then we add one plus three,
112
00:06:34,150 --> 00:06:36,300
and that gives us four,
113
00:06:36,300 --> 00:06:41,220
and so that means that we're taking the square of four,
114
00:06:42,490 --> 00:06:46,500
and that gives us 16,
115
00:06:46,520 --> 00:06:51,560
and that means that the value of this overall expression is
116
00:06:51,560 --> 00:06:58,260
going to be 16.
117
00:06:58,260 --> 00:06:59,415
Here on line four,
118
00:06:59,415 --> 00:07:02,330
we're printing out square of Y plus square of X,
119
00:07:02,330 --> 00:07:05,990
so Python again, you can think of it as competing from the inside out,
120
00:07:05,990 --> 00:07:09,680
so Python is going to replace X with two,
121
00:07:09,680 --> 00:07:13,605
so that means that square of two,
122
00:07:13,605 --> 00:07:17,000
the value of this expression is going to be four,
123
00:07:17,000 --> 00:07:19,220
when we add Y,
124
00:07:19,220 --> 00:07:22,520
whose value is one to four,
125
00:07:22,520 --> 00:07:24,335
then we get five,
126
00:07:24,335 --> 00:07:29,615
so that's you're taking the square of one plus four,
127
00:07:29,615 --> 00:07:31,190
or the square of five,
128
00:07:31,190 --> 00:07:34,820
and then when we take the square of five,
129
00:07:34,820 --> 00:07:40,330
then the value of this overall expression is going to be 25.
130
00:07:40,760 --> 00:07:43,245
In this third example,
131
00:07:43,245 --> 00:07:46,155
we're taking sub square of Y,
132
00:07:46,155 --> 00:07:50,090
and square of X, so Python first asks what's the value of Y,
133
00:07:50,090 --> 00:07:52,000
for Y it gets one,
134
00:07:52,000 --> 00:07:54,975
and then square of one, is going to be one,
135
00:07:54,975 --> 00:07:56,625
and that's whats the value of X,
136
00:07:56,625 --> 00:08:00,570
that's two, it takes square of two, to get four,
137
00:08:00,570 --> 00:08:06,270
and then so we're calling sub with one as the first argument,
138
00:08:06,270 --> 00:08:08,145
and four as the second argument,
139
00:08:08,145 --> 00:08:12,495
and that's going to give us one minus four, or negative three.
140
00:08:12,495 --> 00:08:15,930
So, you'll see that's what gets printed out for this line,
141
00:08:15,930 --> 00:08:18,705
and 25 gets printed out here,
142
00:08:18,705 --> 00:08:22,300
and 16 gets printed out for line three.
143
00:08:23,630 --> 00:08:27,150
That's all for now. Until next time.11267
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.