B · Structure · beginner · Week 2 · Chapter 4 of 13
Functions, modules & packages
def, return, default args, type hints lite, import, project layout with src/ and tests/.
Path progress26%
Step 1 of 3
Write functions
Pure functions first — same input, same output, no side effects. Easier to test.
Example
def is_valid_email(s: str) -> bool:
return "@" in s and "." in s.split("@")[-1]Do this now
Write is_valid_email(s), normalize_phone(s), build_url(base, path).
Was this step clear?
Chapter learning outcomes
- Functions and returns
- Default arguments
- Modules and imports
- Type hints lite
Clear these before you leave
Side quest
Config loader
load_config(path) → dict with try/except for missing file.