Concept Flow - Importing specific items
Start
Write import statement
Python loads module
Extract specific items
Use imported items in code
End
This flow shows how Python imports only the specified items from a module and makes them ready to use.
from math import sqrt, pi result = sqrt(16) circle_area = pi * 2 ** 2 print(result, circle_area)
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Import sqrt and pi from math | sqrt and pi are loaded | sqrt=function, pi=3.141592653589793 |
| 2 | Calculate sqrt(16) | sqrt(16) | 4.0 |
| 3 | Calculate circle_area = pi * 2 ** 2 | 3.141592653589793 * 4 | 12.566370614359172 |
| 4 | Print result and circle_area | print(4.0, 12.566370614359172) | 4.0 12.566370614359172 |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| result | undefined | 4.0 | 4.0 | 4.0 |
| circle_area | undefined | undefined | 12.566370614359172 | 12.566370614359172 |
Import specific items using: from module_name import item1, item2 This loads only those items directly, so you can use them without module prefix. Useful to keep code clean and simple.