Lesson 12 of 55
9 mins readPython Auxiliary Bindings with where Clauses
In Plain English
A where clause defines local variables and helper functions at the end of a function, sharing bindings across all guards in that function.
Deep Dive: How It Works
where vs let: where is a syntactic construct at the end of a function declaration, accessible across all guards. let is an inline expression.
Shared Scope Across Guards: Variables in where are in scope for all guard conditions above.
Core Rules to Remember

Shared Across All Guards: Bindings defined in where can be used in every guard of the function.

Top-Down Readability: Read the main equation first, followed by supporting definitions in where.
Live Interactive Example
Hit Run Code to see it liveBMI Category with where Clause
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Output Console
Click "Run Code" to view the rendered output.
How it works: bmi is calculated once in where and evaluated across all 4 guard branches.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Calculate Circle Properties with where
Define `circleCircumference r = 2 * p * r where p = 3.14159`.
Print `"Circumference: "` followed by `show (circleCircumference 10.0)`.
1
2
3
4
5
6
7
8
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.