Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHanwen Zhang
20,084 PointsWhat does the character import Theft work in the video? In the repl?
what does the word import means generally in python
1 Answer
Mel Rumsey
Treehouse ModeratorHi Hanwen Zhang!
Importing is when you are accessing a different python script
or python module
from your working python file. For example, If you are wanting to get a random number between 1 and 10, there is a python module
that you can access called random
which contains a randint() function. When you import random
you are gaining access to everything that module contains. So when you call random.randint(1,10)
that is accessing the random module, calling the randint()
function, and passing in the required arguments.
What Kenneth is doing when importing random is he is also using the randint() function, but only for the numbers 0 and 1 because the integer 0
is falsy
and 1
is truthy
.
You can read up more on importing here! Hope this helps!
Hanwen Zhang
20,084 PointsHanwen Zhang
20,084 PointsThank you Mel