From the course: Learning Python (2021)
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Conditional structures - Python Tutorial
From the course: Learning Python (2021)
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
-
-
-
-
Building Hello World9m 5s
-
(Locked)
Variables and expressions11m 44s
-
(Locked)
Python functions11m 52s
-
(Locked)
Conditional structures8m 17s
-
(Locked)
Loops9m 28s
-
(Locked)
Classes10m 30s
-
(Locked)
Importing and using modules2m 22s
-
(Locked)
Using exceptions5m 10s
-
(Locked)
Solution: Palindromes2m 37s
-
-
-
-
-