Syntax Basics

Python syntax will feel weird for exactly one day — then it clicks. Five ideas, one reel.

▶ Watch this reel

What you'll learn

  1. Dynamic typing
  2. Indentation & blocks
  3. f-strings & formatting
  4. None & truthiness
  5. Operators & ranges

Remember this

Dynamic typing

Indentation & blocks

f-strings

f"Total: {price:.2f}"      # format spec inside braces
f"{n:,}"                   # thousands separators
f"{name.upper()} ok"       # any expression

None & truthiness

FalsyTruthy
None, False, 0, "", [], {}, ()everything else

Operators

Code: Syntax basics in 20 lines

# Dynamic typing — name tags, not declarations
price = 19.99
label = "pro"
price = label          # legal! the tag moves to a string

# Indentation is the block
if price == "pro":
    print("Pro plan")
    print("  unlimited reels")
print("always runs")   # dedented → outside the if

# f-strings: interpolation + formatting
rows = 1_234_567
print(f"Imported {rows:,} rows in {0.847:.2f}s")

# Truthiness
items = []
if not items:          # same as: if len(items) == 0
    print("empty list is falsy")

if price is None:
    pass               # explicit None check with `is`

# in + range
for i in range(3):     # 0, 1, 2
    if "pro" in label:
        print(f"  step {i + 1} of 3")