1
00:00:04,260 --> 00:00:10,780
In Python, an expression is anything that
can be calculated to return a value.

2
00:00:10,780 --> 00:00:14,480
So on line 4, we've got the expression a + b.

3
00:00:14,480 --> 00:00:18,540
Python evaluates that expression and prints the value 15.

4
00:00:18,540 --> 00:00:23,860
On the next line, we've got a - b, and that evaluates to the value 9.

5
00:00:23,860 --> 00:00:30,100
So working down the code, a multiplied by b is also an expression, evaluating to 36.

6
00:00:30,100 --> 00:00:34,780
Now the next two are similar, a / b and a integer divide by b.

7
00:00:34,780 --> 00:00:40,440
Now they evaluate to 4, but the first one is a floating point value and the second is an int.

8
00:00:40,440 --> 00:00:45,700
And finally on line 9, we've got the expression a and its remainder operator b.

9
00:00:45,700 --> 00:00:49,980
Oh, I said finally there, but it's not actually the last expression in the code.

10
00:00:49,980 --> 00:00:53,600
There are two more expressions on lines 1 and 2,

11
00:00:53,600 --> 00:00:59,580
and it may not be obvious but, strictly speaking, 12 & 3 are also expressions.

12
00:00:59,580 --> 00:01:05,220
They evaluate to the values 12 and 3, respectively, but they're still, technically, expressions.

13
00:01:05,220 --> 00:01:10,620
That means you can use a literal value, anywhere that Python expects an expression.

14
00:01:10,620 --> 00:01:13,440
Now there's also four more expressions at the end of the program,

15
00:01:13,440 --> 00:01:16,960
but I'd only expect you to identify two of them, at the moment.

16
00:01:16,960 --> 00:01:20,620
So can you spot more expressions in the code, after line 9?

17
00:01:20,620 --> 00:01:27,120
Pause the video if you need to, and come back when you've found two more.

18
00:01:27,120 --> 00:01:29,360
Alright so welcome back, did you spot them?

19
00:01:29,360 --> 00:01:35,080
Well firstly, on line 13, we've got the literal value 1 inside the parentheses,

20
00:01:35,080 --> 00:01:40,880
and it evaluates, not surprisingly, to the value 1, but again, it's still an expression.

21
00:01:40,880 --> 00:01:46,940
Now also inside the parentheses, we've got a integer divide by b, and that's the two slashes.

22
00:01:46,940 --> 00:01:53,480
At the moment, that evaluates to 4 because a is currently 12 and b is 3.

23
00:01:53,480 --> 00:01:57,520
So these are the two expressions I
expected you to find, but there are more.

24
00:01:57,520 --> 00:02:03,120
So still on line 13, the two expressions
we've identified are part of another expression.

25
00:02:03,120 --> 00:02:08,759
So the code range parentheses, and then it's 1, a // by b.

26
00:02:08,759 --> 00:02:12,580
That evaluates to a range of numbers from 1 to 3.

27
00:02:12,580 --> 00:02:18,080
So python has to evaluate that, in order to work out what values to use in the loop.

28
00:02:18,080 --> 00:02:25,840
So it evaluates the expression 1 to get the
value 1, and then a // b to get the value 4.

29
00:02:25,840 --> 00:02:31,200
Once it's done that, it has to evaluate range(1, 4).

30
00:02:31,200 --> 00:02:33,160
So that's another expression.

31
00:02:33,160 --> 00:02:38,620
We haven't covered for loops and ranges yet, which is why I wouldn't have expected you to find that expression,

32
00:02:38,620 --> 00:02:41,520
But there's also another one on line 14.

33
00:02:41,520 --> 00:02:46,760
The variable i has to be evaluated so that Python knows what to print.

34
00:02:46,760 --> 00:02:54,700
The first time around the loop, it evaluates to the value 1, next time around it's 2 and the last time around it evaluates to 3.

35
00:02:54,780 --> 00:02:59,080
But hang on a minute, if i on line 14 is an expression,

36
00:02:59,080 --> 00:03:02,040
what about a and b on line 4?

37
00:03:02,040 --> 00:03:04,500
Aren't they also an expression?

38
00:03:04,500 --> 00:03:05,620
Yes they are.

39
00:03:05,620 --> 00:03:10,380
Python evaluates a to get the value 12,
and b to get the value 3.

40
00:03:10,380 --> 00:03:17,940
It then adds them, evaluating the expression 12 + 3, and the same thing happens on lines 5 through 9.

41
00:03:17,940 --> 00:03:20,940
So expressions can themselves, be made up of expressions.

42
00:03:20,940 --> 00:03:25,020
In total there were 26 expressions in this code.

43
00:03:25,020 --> 00:03:28,100
Now we'll look at more complex expressions in the next video,

44
00:03:28,100 --> 00:03:32,380
but I'll finish this one by talking about a and b on lines 1 and 2.

45
00:03:32,380 --> 00:03:34,240
They're not expressions.

46
00:03:34,240 --> 00:03:37,840
You can't have an expression on the left of an assignment.

47
00:03:37,840 --> 00:03:41,060
The expression on the right of the equals sign is evaluated,

48
00:03:41,060 --> 00:03:44,340
and the variable on the left is bound to the result.

49
00:03:44,340 --> 00:03:49,680
So a common way of saying that is to say, the value 12 is assigned to the variable a,

50
00:03:49,680 --> 00:03:55,180
but I want to get you used to the idea that we bind, or attach variables to values.

51
00:03:55,180 --> 00:04:00,880
The result is the same. Whenever we refer to a in the code, Python evaluates it as 12.

52
00:04:00,880 --> 00:04:04,100
Okay, so what about i on line 13.

53
00:04:04,100 --> 00:04:06,460
Well that's also not an expression.

54
00:04:06,460 --> 00:04:11,760
i is being bound to each of the values produced by range in turn.

55
00:04:11,760 --> 00:04:14,680
So if I write this code long handed instead of using a for loop,

56
00:04:14,680 --> 00:04:19,380
it should become more obvious. So I'll come down here and I'll start on line 16.

57
00:04:19,380 --> 00:04:22,280
So put i equals 1,

58
00:04:22,280 --> 00:04:28,480
and on line 17 I'm gonna do print parentheses i, then i equals 2,

59
00:04:28,480 --> 00:04:32,342
print i, i equals 3, print i.

60
00:04:32,342 --> 00:04:38,160
Alright, I'll just move that up a bit.

61
00:04:38,160 --> 00:04:44,020
So that does exactly the same thing, where that would take six lines of code instead of two,

62
00:04:44,020 --> 00:04:46,060
which I've got on lines 13 and 14.

63
00:04:46,060 --> 00:04:49,920
But when I run the program,

64
00:04:49,920 --> 00:04:52,760
we get the same three values printed out again.

65
00:04:52,760 --> 00:04:57,540
So if i on lines 16, and i'll just scroll us up so we can see it,

66
00:04:57,540 --> 00:05:02,000
so lines 16, 18 and 20. So if I on those lines isn't an expression,

67
00:05:02,000 --> 00:05:08,900
then it should be clear that it's not an expression on line 13 either.

68
00:05:08,900 --> 00:05:11,820
Alright, so you'll see why we don't have i = 4 later.

69
00:05:11,820 --> 00:05:17,520
I'll stop the video here now, though, and we'll look at operator precedence in the next video.

