Use the conditional expression Python 3


show more Using the conditional expression provides you with in-depth training on Developer. Taught by Bill Weinman as part of the Python 3 Essential Training show less
please wait ...

Using the conditional expression

One other type of conditional structure in Python is the conditional expression. Let's make a working copy of conditionals.py, conditionals-working.py and we'll open up that working copy, and we'll go ahead and assign a couple of variables. Now, a lot of times, all you're doing with a conditional is something like this. if a is less than b, then V equals this is true, else, V equals this is not true and print v.

You'll see this kind of a thing a lot in a lot of different languages. We save that and run it, say this is true, and if the condition is otherwise, save and run. It says this is not true. So, in Python, there's a much, much easier way to do this. You can simply say v equals this is true if a is less than b, else, this is not true, And so that takes all of this, and it basically puts it in an expression.

So delete that, and I save and run, and we get exactly the same results. Make that a 0 and it'll say this is true, and this is true. So, all we've do...

Using the conditional expression
Video duration: 2m 28s 6h 36m Beginner

Viewers:

Using the conditional expression provides you with in-depth training on Developer. Taught by Bill Weinman as part of the Python 3 Essential Training

Subjects:
Developer Web
Software:
Python
Author:
please wait ...