import: borrow code someone already wrote
You don't have to build everything yourself. import lets you borrow ready-made tools — like a star stamp and a flower stamp — and use them right away.
The big idea
import brings code from another place into your program, so you can use its tools as if you wrote them.
See it in code
Python ships with ready-made tools. The math box already knows square roots — we don't rewrite that, we borrow it. from math import sqrt grabs just that one tool, and we use it right away:
from math import sqrt
print("The square root of 49 is", sqrt(49))The square root of 49 is 7.0
We never wrote the square-root math — math did. The import line is what let us reach in and grab sqrt.
You can grab more than one tool on the same line. Here we borrow sqrt and floor (which rounds a number down to a whole number):
from math import sqrt, floor
print(sqrt(49))
print(floor(4.8))7.0 4
Two names after import, separated by a comma, so we borrowed two tools at once. Every tool you use has to be on that line.
Now our own toolbox. The art package already knows how to draw a perfect star and a perfect flower. We don't rewrite them — from art import Canvas, star, flower grabs three tools at once, just like before. Then we use them:
from art import Canvas, star, flower
screen = Canvas.create()
Canvas.fill(screen)
star(screen, 160, 250, size=90)
flower(screen, 340, 250, size=90)
We never wrote the math for a star's five points — art did. Importing let us stand on top of someone else's work.
Every real program imports. Games import their game pieces, artists import color palettes, and Python itself ships with hundreds of ready-made tools. Learning to borrow code is how small programs do big things.
Try it yourself
Add another star near the top with star(screen, 250, 120). Then try to draw a heart(...) — Python will complain, because you only imported star and flower. Every borrowed tool needs to be on the import line.
The common mistake
Using a tool you forgot to import. If you call star(...) but never wrote from art import star, Python says it does not know what star is. Each borrowed tool needs its import line first.
What it unlocks
Once you can import, you can pull in the random module to scatter stars, and reach for for loops to stamp a whole row of them.