From the course: Learning Python

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Conditional structures

Conditional structures - Python Tutorial

From the course: Learning Python

Conditional structures

- [Instructor] One of the most common operations of almost any program is making decisions. Your program will often need to compare different values and execute code based upon some logical outcome. And that's where conditional logic comes into play. So in the code editor, I'm going to open up "conditionals_start" and in Python, conditionals are handled using the "if" statement. And so you can see here in the main function, I've got two variables, X and Y, and they are 10 and 100 to start with. So let's go ahead and add our first conditional statement. I'm going to write "if X is less than Y" and then I'm going to assign the "result" variable to the string "X is less than Y." And then I'll just print out the result. All right. So the code compares X to Y and if X is less than Y, then you can see we set the value of this result variable and then we print it. So let's run it. And I'm going to run this in my terminal…

Contents