Python Tutorial Python Advanced Python References Python Libraries

Python from Keyword



The Python from keyword is used to import a specified section from a module. The modules from which the section need to be imported must be installed on the local computer or a remote computer. The imported section of the module can be used in the current session using its name only and passing the required parameter if has any.

Syntax

#import section/object from module
from ModuleName import SectionName

#use section/object of a module
SectionName(parameters)

Example:

In the example below, the object called pi is imported from the module called math in the current session. The imported object pi is further used to calculate the area of a circle.

from math import pi

radius = 1
area = pi*(radius)**2

print(area)

The output of the above code will be:

3.141592653589793

❮ Python Keywords