Python import Keyword/Statement

The import keyword or statement in Python, is used when we need to import or load modules in a program. For example:

import datetime


The sample output of this program is:

2021-12-20 08:39:51.731020

The import keyword used in above program, to import the datetime module to print the current date and time.

Python import Keyword/Statement Example

Here is another program, demonstrating the use of import to load the module in a program. This program uses import to load random module:

import random


The sample output is:


Every time, you execute the program, you'll get different random number.

Python Online Test

« Previous Tutorial Next Tutorial »

Follow/Like Us on Facebook

Subscribe Us on YouTube