Python as Keyword
The Python as keyword is used to create an alias while importing a module in the current session. Creating an alias means giving a user-defined name to the module while importing it. After creating an alias, the object of the module can be used in the current session with the user-defined name followed by a dot (.) and object name.
Please note that the modules which need to be imported must be installed on the local computer or a remote computer.
#import module as alias name import ModuleName as NewName #use object of a module NewName.ObjectName(parameters)
In the example below, the math module is imported in the current session with user-defined name called m. The math module contains an object called pi which is used in the current session to calculate the area of a circle.
import math as ma radius = 1 pi = ma.pi area = pi*(radius)**2 print(area)
The output of the above code will be:
❮ Python Keywords