In real life, decisions are made based on conditions — if it rains, carry an umbrella; otherwise, you are fine without one.
Python works the same way. Conditional statements allow a program to make decisions and execute different blocks of code based on whether a condition is true or false. They are one of the most fundamental and frequently used tools in programming.
The if Statement
The if statement checks a condition. If the condition is True, the indented block of code beneath it runs. If it is False, Python skips it.
Syntax:

Example:


The else Statement
The else statement provides an alternative block of code that runs when the if condition is False. Think of it as the fallback option.
Syntax:

Example:


elif stands for else if. It allows you to check multiple conditions in sequence. Python evaluates each condition from top to bottom and executes the first one that is True.
Syntax:




You can place an if statement inside another if block. This is called nesting, and it is useful when a decision depends on multiple layers of conditions.


Use nesting carefully — too many levels make code hard to read.
Shorthand if — One-Line Conditionals
For simple conditions, Python allows a compact one-line version called a ternary expression.


This is clean and readable for simple true/false decisions, but avoid using it for complex logic.
Common Mistakes to Avoid

We have a sales campaign on our promoted courses and products. You can purchase 1 products at a discounted price up to 15% discount.