1
00:00:00,000 --> 00:00:02,990
One other type of conditional structure in Python is the

2
00:00:03,000 --> 00:00:04,990
conditional expression.

3
00:00:05,000 --> 00:00:11,990
Let's make a working copy of conditionals.py, conditionals-working.py and we'll

4
00:00:12,000 --> 00:00:18,990
open up that working copy, and we'll go ahead and assign a couple of variables.

5
00:00:19,000 --> 00:00:25,990
Now, a lot of times, all you're doing with a conditional is something like this.

6
00:00:26,000 --> 00:00:42,990
if a is less than b, then V equals this is true, else, V equals this is not true and print v.

7
00:00:43,000 --> 00:00:45,990
You'll see this kind of a thing a lot in a lot of different languages.

8
00:00:46,000 --> 00:00:52,990
We save that and run it, say this is true, and if the condition is

9
00:00:53,000 --> 00:00:54,990
otherwise, save and run.

10
00:00:55,000 --> 00:00:57,990
It says this is not true.

11
00:00:58,000 --> 00:01:00,990
So, in Python, there's a much, much easier way to do this.

12
00:01:01,000 --> 00:01:09,990
You can simply say v equals this is true if a is less than b, else, this is not

13
00:01:10,000 --> 00:01:12,990
true, And so that takes all

14
00:01:13,000 --> 00:01:16,990
of this, and it basically puts it in an expression.

15
00:01:17,000 --> 00:01:23,990
So delete that, and I save and run, and we get exactly the same results.

16
00:01:24,000 --> 00:01:29,990
Make that a 0 and it'll say this is true, and this is true.

17
00:01:30,000 --> 00:01:34,990
So, all we've done here is we've taken that whole if-else structure and we put

18
00:01:35,000 --> 00:01:35,990
it in an expression.

19
00:01:36,000 --> 00:01:39,990
And Python has several of these, and we'll cover these throughout the course,

20
00:01:40,000 --> 00:01:43,990
but it's a convenient shorthand, and you'll notice that it even reads well.

21
00:01:44,000 --> 00:01:47,990
v equals this is true if a is less than b, else, this is not true

22
00:01:48,000 --> 00:01:53,990
And so this part here is what makes it a conditional expression.

23
00:01:54,000 --> 00:01:59,990
You have if, and you have the expression that evaluates true or false, and else,

24
00:02:00,000 --> 00:02:00,990
and then a second value.

25
00:02:01,000 --> 00:02:06,990
So, without all of this, you would simply have v equals this is true,

26
00:02:07,000 --> 00:02:11,990
and with all of this, you have a conditional expression, this is true or this is not true,

27
00:02:12,000 --> 00:02:16,990
depending on the evaluation of this conditional expression.

28
00:02:17,000 --> 00:02:20,990
So, that's a conditional expression in Python, and it's a very convenient

29
00:02:21,000 --> 00:02:24,990
shorthand for a lot of cases where you would otherwise use four lines of if

30
00:02:25,000 --> 00:02:35,000
and else.

