• Python Basics

  • Python Variables

  • Operators in Python

  • Conditional Statements in Python

  • Python Lists

  • Python Tuples

  • Python Sets

  • Python Dictionaries

  • Loops in Python

  • Python Arrays and Functions

  • Conclusion

Nested if statement in Python

Nested If

You can have if statements inside other if statements, which is known as nested if statements.

Example:

python
1x = 41
2if x > 10:
3    print("Above ten,")
4    if x > 20:
5        print("and also above 20!")
6    else:
7        print("but not above 20.")

The Pass Statement

If an if statement cannot be empty, but you want to write an if statement with no content, use the pass statement to avoid getting an error.

Example:

python
1a = 33
2b = 200
3if b > a:
4    pass  # This will not produce an error

Frequently Asked Questions