Language

Modules · Lesson 17 of 56

Import

Source: 5-Modules/5.1-import.ipynb

Start here — no coding background needed

What you will learn

Use built-in or your own code files without rewriting.

In simple words

`import math` brings ready-made tools. You call `math.sqrt(16)` instead of writing square root yourself.

Reuse code others wrote — like apps on your phone you did not build yourself.

Easy example — try this first

Easy example — run this first. Change values and press Run again.

Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference notes (from full bootcamp)

Optional — deeper detail for when you are ready

Importing Modules in Python: Modules and Packages

In Python, modules and packages help organize and reuse code. Here's a comprehensive guide on how to import them.

Reference example
Python
Output
Expected (from notebook):
4.0

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
4.0
5.0
3.141592653589793

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
array([1, 2, 3, 4])

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
4.0
3.141592653589793

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
5

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
5

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Conclusion

Importing modules and packages in Python allows you to organize your code, reuse functionalities, and keep your projects clean and manageable. By understanding how to import modules, specific functions, and use relative imports within packages, you can structure your Python applications more effectively.

Practice test — try yourself

Write code, press Check. Wrong answer shows the correct code to copy & run.

You learned "Import". Use print() to show: Done: Import

Hint: Use one print() with the exact text.

Python