Python Functions Lab

Functions are one of the most powerful tools in Python. They let you write a piece of logic once and reuse it across different inputs, eliminating the need to copy and paste the same code block every time your data changes. This is the foundation of automation in data work.

It also turns out you have been using functions all along. The libraries at the center of this course, i.e., pandas, geopandas, shapely, are fundamentally just large, carefully organized collections of pre-written functions and classes. Their closest cousins are methods: the commands you attach directly to your data using dot notation, like df.head() or gdf.plot(). Same idea, slightly different form.

This lab builds your mental model from the ground up: what a function is made of, how Python executes it, and how to write one correctly.

What you will practice:

  • Reading a function signature and identifying its parts (name, parameters, type hints, return type)
  • Assembling function bodies in the correct order with correct indentation
  • Completing partially-written functions by filling in missing pieces
  • Naming each structural element of a function using precise vocabulary
  • Calling a function with your own inputs and seeing the real output

The lab has seven activities across four modes — Assemble, Fill the Gaps, Matching, and a Try It REPL at the bottom of every coding exercise that runs your assembled function directly in the browser. No install required.


Open the lab in a new tab:

Open Python Functions Lab

Activities at a glance:

# Mode Function What you practice
1 Assemble greet(name: str) Order and indent a 3-line function
2 Matching greet() Name every structural part of a function
3 Assemble clean_column_names(df) Chain .str accessor methods to vectorize column name cleaning
4 Assemble celsius_to_f(c: float) Arithmetic expression, single return
5 Fill the Gaps absolute_value(n: float) Conditional with early return
6 Fill the Gaps classify_grade(score: int) if / elif / else chain; type hints in signatures
7 Matching classify_grade() Name conditional structure: branch, elif, comparison operator

Preview:

Preview only — interactions are disabled. Open full lab →

© 2026 Maryam Hosseini


This site uses Just the Docs, a documentation theme for Jekyll.