Conditionals
Making decisions
To be useful, programs often need to make decisions, that is, carry out certain actions based on whether certain conditions are met or not. This branching behavior stands on two legs:
- Boolean expressions: Python expressions that produce a true or false value
- Conditional logic:
ifandif-elsestatements. Decide whether to execute blocks of code based on the value of a boolean expression.
In this lesson we look at:
- How to produce true or false values
- How to test the value of a boolean expression using
ifstatements - Code blocks and indentation in Python
- How to write programs that behave differently based on input
- More on string manipulation in Python, including string formatting