Boston Python Workshop 4/ColorWall handout: Difference between revisions

no edit summary
imported>Jesstess
imported>Jesstess
No edit summary
Line 108:
bbb
ccc</pre>
 
====Imports====
 
Imports look like this:
 
<pre>
>>> import random
>>> import time</pre>
 
In the above example, <code>random</code> and <code>time</code> are both Python modules. Modules
are Python files outside of the current Python file that contain
Python code, like functions and variables. You can use code from
modules by first importing the module. Here's an example from the
<code>random</code> module:
 
<pre>
>>> import random
>>> random.randint(0, 10)
7
>>> random.randint(0, 10)
6
>>> random.randint(0, 10)
1
>>> random.randint(0, 10)
3
>>> random.randint(0, 10)
4
>>> random.randint(0, 10)
9</pre>
 
<code>randint</code> is a function in the <code>random</code> module. It takes a lower bound as
the first argument and an upper bound as the second argument and
returns a random integer between those bounds.
Anonymous user