CHAPTER 20   •   PYTHON

Python Nested If

Learn how to place one if statement inside another.

01 What is this?

Learn how to place one if statement inside another.

02 Syntax

Python Syntax
if condition:
    if condition:

03 Example

Python Example
age = 20
student = True

if age >= 18:
    if student:
        print('Adult student')

04 Important Points

Nested conditions require careful indentation.

05 Common Mistakes

Avoid unnecessary nesting when simpler logic is possible.

06 Real World Use

Nested conditions can be used for multi-level validation.

07 Practice This Topic

Now try the example yourself in the AIFA Python Editor.

  • Read the example carefully.
  • Change the values.
  • Run the code.
  • Observe the output.
  • Try creating your own example.
Try It Yourself →