Lesson 01 · foundations

Python Syntax, Fast

Same ideas you already have — for, if, functions — new punctuation.

You already know what a variable, a loop, a conditional, and a function are. This lesson is not about those concepts — it's a fast map from concepts you have to Python's specific syntax for them, so you can write and run a real script by the end.

Running a script

Two ways you'll use constantly:

# save as hello.py, then:
python3 hello.py

# or start an interactive shell (REPL) — evaluates line by line:
python3
Later Once lessons reach data work, you'll mostly run code in a Jupyter notebook instead of a plain script — cells you re-run individually. Not needed yet.

The one big rule: indentation is the block

Languages with { } or begin/end use punctuation to mark a block. Python uses a colon and indentation — the whitespace is the syntax, not a style choice.

Brace-style language

if (x > 0) {
    print(x);
}

Python

if x > 0:
    print(x)
The classic mistake Mixing tabs and spaces, or indenting one line differently than its siblings, is a syntax error in Python — not a lint warning. Pick spaces (4 is the convention) and let your editor handle it consistently.

Variables need no type

No int x = 5;. A name is just bound to a value, and can be rebound to a different type later (usually a code smell, but legal):

age = 27          # int
name = "Ada"      # str
pi = 3.14         # float
is_ready = True   # bool — capitalized, no quotes

print(f"{name} is {age}")   # f-string: {expr} interpolated inline
Naming convention Python variables and functions are snake_case, not camelCase. This isn't optional style — every library you'll read (including pandas) follows it, so code that doesn't looks foreign.

Functions and control flow, together

One block, all the pieces from above in context:

def classify(n):
    if n < 0:
        return "negative"
    elif n == 0:
        return "zero"
    else:
        return "positive"

numbers = [-2, 0, 5, 17]

for n in numbers:
    print(n, "→", classify(n))

Notice: no return type declared, no semicolons, the for loop iterates directly over a collection (no index bookkeeping unless you ask for it), and def needs no parameter types.

Do this now (5 minutes)

Write and run a real script — don't just read the one above:

# save as fizzbuzz.py
def fizzbuzz(n):
    if n % 15 == 0:
        return "FizzBuzz"
    elif n % 3 == 0:
        return "Fizz"
    elif n % 5 == 0:
        return "Buzz"
    else:
        return str(n)

for i in range(1, 21):
    print(fizzbuzz(i))

Run it: python3 fizzbuzz.py. If it prints 20 lines ending in 19, FizzBuzz — indentation, function, loop, and conditional all landed correctly.

Your win You've mapped variables, functions, conditionals, and loops onto Python's actual syntax, and run a script that uses all four together. Next lesson builds the data structures (lists, dicts) you'll lean on constantly once real datasets show up.

Go deeper

Primary source — read this one: The Python Tutorial §4, "More Control Flow Tools". Covers if, for, range, and def in the authoritative detail this lesson compressed.