My App
Phase 1 — Core Foundations

if / elif / else

Conditionals, including nested conditions

if

JavaScript:

if (age >= 18) {
  console.log('Adult');
}

Python:

if age >= 18:
    print("Adult")

Notice:

JS/TSPython
{ }indentation
( ) around conditionnot required
;not required

elif

JavaScript's else if becomes Python's elif.

if (age >= 18) {
  console.log('Adult');
} else if (age >= 13) {
  console.log('Teen');
} else {
  console.log('Child');
}
if age >= 18:
    print("Adult")
elif age >= 13:
    print("Teen")
else:
    print("Child")

Nested conditions

You'll see this kind of logic a lot in backend code.

age = 25
is_active = True

if age >= 18:
    if is_active:
        print("Active adult user")

On this page