Nesting means writing one conditional statement inside another.
example
age = 20
has_id = True
if age >= 18:
if has_id:
print("You can vote")
else:
print("You need an ID")
else:
print("You are underage")output
You can voteSyntax:
if condition1:
if condition2:
print(" ")Important
- Inner
ifruns only if outerifisTrue- Use proper indentation
- Avoid too much nesting (makes code hard to read)