Modules, imports, and packages

What happens when another file imports total from prices?

Examples

Worked example

Input
prices.py defines total and has an unguarded print
Expected output
The top-level print runs.

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

Importing the module runs its top-level code before the requested name is made available.

Back to the lesson