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

import


Related: Python tutorial - modules

 Examples

 
 
import random

 Description        

 
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.

 Syntax

 
 
import module_name

 Parameters

 
module_name - module name to be imported

 Interpreter

 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)

5

>>> 

>>> random

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





Comments