-
Book Overview & Buying
-
Table Of Contents
Python Illustrated
By :
In this chapter, we learned how to work with conditional statements, which are ways to let Python make decisions based on specified conditions.
A condition is a statement that evaluates to a boolean value: either True or False. We also learned about the correct syntax for conditional statements and that the code block must be indented correctly for it to work. The comparison operators we studied in the previous chapter came in handy when we played around with different conditional statements. To specify what should happen if an if condition is not met, we practiced using the else statement:
bites = True
is_cute = True
if not bites and is_cute:
print("You want to pet that dog")
else:
print("Do not pet that dog")
For scenarios with more than two possibilities, we discovered the elif statements and the match statement, which help simplify lengthy if-else chains.
Let’s not forget about the logical operators. We used the following...