Python online course

Control flow

Branch with if/elif/else and repeat work with for and while.

Scripts need to choose a path and repeat work. Python uses indentation, not braces, so the visual block is the real block.

Decisions

status = 404
if status == 200:
    print("ok")
elif 400 <= status < 500:
    print("client error")
else:
    print("something else")

Comparisons you will use constantly: ==, !=, <, >, in, and not. Combine conditions with and / or, and put the cheapest check first.

Loops

for octet in [10, 0, 0, 1]:
    print(octet)

tries = 0
while tries < 3:
    tries += 1

for walks a sequence. while keeps going until a condition fails — give it a clear stop, or you will spin forever. break leaves the loop early; continue skips to the next pass.