Manuals / Python / Chapter 4

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 progress
26%

Step 1 of 3

Write functions

Pure functions first — same input, same output, no side effects. Easier to test.

Write functionsDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Write functionsdrag · tap →Try thisdrag · tap →Follow the dashed drag · tap →

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.