VOOZH about

URL: https://www.geeksforgeeks.org/python/python-if-else/

⇱ Python If Else Statements - Conditional Statements - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python If Else Statements - Conditional Statements

Last Updated : 21 May, 2026

If-Else statements are conditional statements used to perform decision-making in a program. They allow different blocks of code to execute based on whether a condition is True or False.

if Statement

The if statement is used to execute a block of code only when a given condition is True. If the condition is False, the code inside the if block is skipped.

👁 if---------statement
If Statement

Output
I am Not in if

if-Else Statement

The if-else statement is used to execute one block of code when a condition is True and another block when the condition is False. It helps programs make decisions based on different conditions.

👁 if---------else---------statement
If-else Statement

Output
i is positive

If-Else in One line

If we need to execute a single statement inside the if or else block then one-line shorthand can be used.


Output
Negative

Logical Operators with If-Else

We can combine multiple conditions using logical operators such as and, or, not.


Output
Eligible.

Nested If-Else Statement

A nested if-else statement is an if-else structure placed inside another if or else block. It is used to check multiple conditions step by step and execute code based on those conditions.

👁 Nested-statement
Nested if Statement

Output
i is smaller than 15
i is smaller than 12 too

if-elif-else Statement

The if-elif-else statement is used to check multiple conditions one by one. When a condition becomes True, its corresponding block of code is executed. If none of the conditions are True, the else block runs.


Output
i is not present

Related Articles:

Comment
Article Tags: