Common Mistakes

Control Flow

Common Mistakes

In this tutorial, we'll avoid assignment, indentation, and comparison traps.

Conditionals are powerful, but a few beginner mistakes appear often.

Mistake 1: Using = Instead of ==

Use = to assign a value:

password = "secret"

Use == to compare values:

if password == "secret":
    print("Access granted")

= and == mean different things.

Mistake 2: Forgetting the Colon

if score >= 50
    print("Pass")

Correct:

if score >= 50:
    print("Pass")

Mistake 3: Wrong Indentation

if score >= 50:
print("Pass")

Correct:

if score >= 50:
    print("Pass")

Python uses indentation to understand blocks.

Mistake 4: Conditions That Are Always True

This looks reasonable but is wrong:

name = "Ada"

if name == "Ada" or "Grace":
    print("Known user")

"Grace" by itself is truthy, so the condition always passes.

Correct:

if name == "Ada" or name == "Grace":
    print("Known user")

Or:

if name in ["Ada", "Grace"]:
    print("Known user")

Mistake 5: Confusing Strings and Booleans

This is a string:

is_ready = "False"

Non-empty strings are truthy, so this condition runs:

if is_ready:
    print("Ready")

Use the real boolean value instead:

is_ready = False

Practice

Write three broken if statements on purpose: one missing a colon, one with bad indentation, and one using = instead of ==. Run them and read the errors.