█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/Programming Languages/Python (Professional)/Python Fundamentals (Modern Python 3.12+)
45 minBeginner

Python Fundamentals (Modern Python 3.12+)

After this lesson, you will be able to: Use modern Python 3.12+ syntax for variables, types, control flow, functions, and modules.

The basics done right. Python 3.12+ has match/case, structural typing, better error messages, use them.

Prerequisites:Python Environment Setup

Modern Python in 50 lines

Read every line; the comments explain idioms most tutorials skip.

python
# Types are inferred but you can annotate
name: str = "Alex"
age: int = 30
active: bool = True
scores: list[int] = [85, 92, 78] # Python 3.9+, no need for List from typing
# f-strings (always use these)
print(f"{name} is {age}")
print(f"{age=}") # 3.8+ debug form: outputs 'age=30'
# Walrus operator (3.8+)
if (n := len(scores)) > 0:
print(f"{n} scores")
# Match (3.10+), like switch but real pattern matching
def classify(value):
match value:
case int() if value > 100: return "big int"
case int(): return "int"
case [first, *rest]: return f"list starting with {first}"
case {"name": name}: return f"dict with name {name}"
case _: return "other"
# Functions with type hints + defaults
def greet(name: str, greeting: str = "Hello") -> str:
return f"{greeting}, {name}"
# Keyword-only args (after *)
def build_user(name: str, *, email: str, admin: bool = False) -> dict:
return {"name": name, "email": email, "admin": admin}
# Imports: prefer explicit
from datetime import datetime
import json # standard library
from mypackage.users import get_user # your package

Mutable default trap

Never use `[]` or `{}` as a default. They are SHARED across calls. Use `None` and create inside.

Common mistakes only experienced Python devs avoid

Using mutable defaults. Comparing with `==` when you should use `is` (only for None/True/False/singletons). Catching bare `except:` which swallows KeyboardInterrupt. Writing `for i in range(len(xs)):` instead of `for i, x in enumerate(xs):`. Mixing tabs and spaces.

Quick Check

Why is `def add(item, target=[])` a bug?

Pick the canonical Python gotcha.

Sign in and purchase access to unlock this lesson.

Sign in to purchase
←Python Environment Setup
Back to Python (Professional)
Object-Oriented Python→