Importing and using modules
18-minute lesson · module-modules-01
You are previewing this course as a guest
Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.
Importing and using modules
18-minute lesson · module-modules-01
- Import a standard-library module with `import name`.
- Pull specific names in with `from module import thing`.
- Rename an import with `as` to give it a shorter alias.
- Read a module's contents and call its functions through dotted access.
Source attribution
Status: adapted
How to Think Like a Computer Scientist: Interactive Edition — source · Modules / Modules / More About Using Modules and Functions
Adaptation notes. Reading rewritten in our voice. Examples use an Iowa State CS room-and- roster theme. Hidden tests exercise both an `import math` style call and a `from ... import` / `as` alias so the student practices all three import forms.
License notes. Original chapter is GNU FDL 1.3 (Brad Miller, David Ranum, and the upstream Elkner/Downey/Meyers text). No verbatim text reproduced.