Python Tutorial 14: How to import a python library into a python program

How to import a python library into a python program?

Python as libraries that add functionality to the basic interpreter of Python,

In order to reduce the size of the program and also to maximise the performance., they are not loaded into the basic interpreter by default. To import a python library into a python program. we simply use the import statement.

e.g.

Import python library

 

import random

This will import the random library into the python program.

print(random.randint(0,1000))

The “random” here represent the import library random and the “randint” is a method available from the random library. This comment is actually calling the randint method from the random library with arguement 0 and 1000.

 

For a full list of libraries available from python, please refer to the python library from the following website:

 

https://docs.python.org/3/library/index.html

 

 

Leave a Comment