codescracker
python

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

print(datetime.datetime.today())

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

print(random.random())

The sample output is:

0.20462596685802914

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

Python Online Test


« Previous Tutorial Next Tutorial »



© Copyright 2021. All Rights Reserved.

CodesCracker