Concept Flow - Import aliasing
Start
Import module
Assign alias
Use alias to access module
Program runs with alias
End
The program imports a module and assigns it a short name (alias). Then it uses this alias to access the module's features.
import math as m result = m.sqrt(16) print(result)
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Import math module as 'm' | math module loaded | 'm' refers to math module |
| 2 | Calculate m.sqrt(16) | m.sqrt(16) calls math.sqrt(16) | 4.0 |
| 3 | Assign result = 4.0 | result stores 4.0 | result = 4.0 |
| 4 | Print result | print(4.0) | Output: 4.0 |
| 5 | End of program | No more code | Program stops |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| m | undefined | math module | math module | math module |
| result | undefined | 4.0 | 4.0 | 4.0 |
import module as alias - Imports a module and gives it a short name - Use alias to access module functions - Makes code shorter and clearer - Example: import math as m - Use: m.sqrt(16) instead of math.sqrt(16)