Recall & Review
beginner
What does it mean to import specific items in Python?It means you bring only certain functions, classes, or variables from a module into your program instead of importing the whole module.
Click to reveal answer
beginner
How do you import only the <code>sqrt</code> function from the <code>math</code> module?You write: <br><code>from math import sqrt</code><br>This lets you use <code>sqrt()</code> directly without <code>math.</code> prefix.Click to reveal answer
beginner
What happens if you try to use a function not imported specifically?
You get an error because Python doesn't know about it unless you import it or the whole module.Click to reveal answer
beginner
Can you import multiple specific items from a module at once? How?Yes, by listing them separated by commas: <br><code>from module_name import item1, item2</code>Click to reveal answer
beginner
Why might you prefer importing specific items instead of the whole module?
It keeps your program clean and can save memory by only loading what you need.
Click to reveal answer
Which syntax correctly imports the
choice function from the random module?✗ Incorrect
The correct syntax is
from random import choice to import a specific function.What will happen if you write
import math and then call sqrt(9)?✗ Incorrect
You must use
math.sqrt(9) or import sqrt specifically; otherwise, sqrt alone is undefined.How do you import both
sin and cos from the math module?✗ Incorrect
Use commas to separate multiple items:
from math import sin, cos.What is a benefit of importing specific items instead of the whole module?
✗ Incorrect
Importing only what you need can make your program start faster and use less memory.
Which of these is NOT a correct way to import the
datetime class from the datetime module?✗ Incorrect
You cannot import like
import datetime.datetime. Use from datetime import datetime or import datetime.Explain how to import specific functions from a Python module and why it might be useful.
Think about how you bring only what you need from a toolbox.
You got /3 concepts.
Describe what happens if you try to use a function from a module without importing it specifically or importing the whole module.
Imagine trying to use a tool you never took out of the box.
You got /3 concepts.