Back
+15 XP
Concept

`import module` vs `from module import func`

`import math` requires prefixing calls (`math.pi`). `from math import pi` pulls names directly into local scope. Avoid wildcard imports (`*`).

python
# Namespace qualified:
import math
print(math.pi)

# Direct import:
from math import sqrt
print(sqrt(25))  # 5.0

# 12. `import module` vs `from module import func` `import math` requires prefixing calls (`math.pi`). `from math import pi` pulls names directly into local scope. Avoid wildcard imports (`*`): ```python # Namespace qualified: import math print(math.pi) # Direct import: from math import sqrt print(sqrt(25)) # 5.0 ``` Wildcard imports (`from module import *`) make code unsearchable. When debugging `calculate()`, developers and linters have no way of knowing which imported module provided the function.

Checkpoint

Why is `from module import *` universally banned in professional Python codebases?

Practice

Import only `ceil` and `floor` from `math`. Calculate `ceil(4.2)` and print it.

Terminal
01
Tap code blocks below to assemble
Available Blocks