Q.Example 7.5:
from random import random
random() #Function called without the module name
from random import random
random() #Function called without the module name
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Concept understanding — Module Attribute Access
Module Attribute Access — From Intuition to Precision
Think of a module as a toolbox. When you write import math, you're bringing a whole toolbox into your workspace. Inside that toolbox are tools — functions like sqrt, constants like pi, and other objects. To use a tool, you reach into the box and pick it out. That reaching-in is attribute access.
In Python, every module is an object. And objects have attributes — named pieces of data attached to them. When you write math.pi, you're saying: "from the math object, give me the attribute named pi". The dot (.) is the access operator.
The Intuition: A Labelled Filing Cabinet
Imagine a filing cabinet with labelled drawers. The cabinet is the module. Each drawer has a label — sqrt, pi, sin, cos. To get what's inside a drawer, you open that specific drawer. You don't rummage through the whole cabinet.
import math
print(math.pi) # opens the 'pi' drawer → 3.14159...
print(math.sqrt) # opens the 'sqrt' drawer → <built-in function sqrt>
The dot is your hand reaching for the drawer handle. The name after the dot is the label you're looking for.
The Precise Statement …
Unlock the full solution
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
7-day money-back guarantee · under 100 questions viewed (whichever comes first)