Knowledge Base‎ > ‎Programming‎ > ‎Python‎ > ‎Python Reference‎ > ‎


Related: Python tutorial - modules


import random


Import a module into Python and provides additional features. Many built-in parts of Python (such as random) need to be imported first. Other modules are developed by other developers and need to be downloaded into your program and then imported into your code.


import module_name


module_name - module name to be imported


 Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) 

[GCC 4.0.1 (Apple Inc. build 5493)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> import random

>>> random.randint(1,6)



>>> random

<module 'random' from '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/random.pyc'>