Python TutorialLesson 18Free preview
Python If...Else
This lesson is part of Python · All levels
Summary
Branching allows the program to select blocks of code that are executed based on specific conditions. Python uses if for the initial condition, elif for the additional option, and else as the last option when all previous conditions are False. Conditions can be combined with and, or, and not to make decisions more accurate.
Key points
- Each if block ends with a colon mark followed by an indentation.
- The elif is used to check the condition in sequence.
- Else becomes the last branch to be run when all conditions are satisfied.
- Operator and, or, and not combine or reverse the condition.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.