Home »
Python
as keyword with example in Python
Python as keyword: Here, we are going to learn about the as keyword with example.
Submitted by IncludeHelp, on April 14, 2019
Python as keyword
as is a keyword (case-sensitive) in python, it is used to create an alias of a modules, it is placed while importing a modules after module name.
Syntax of as keyword
import module_name as alias_name
Example:
Import statement:
import math as m
# function call
m.factorial(5)
Output:
120
Python examples of as operator
Example 1: Find factorial of a number by importing math module
# python code to demonstrate an example
# of math module
# import statement
import math
# number
num = 5
# finding factorial
result = math.factorial(num)
# printing factorial
print("Factorial of ", num, " is = ", result)
Output
Factorial of 5 is = 120
Example 2: Find factorial of a number by importing math module by creating alias of module (using as keyword)
# python code to demonstrate an example
# of math module with "as" keyword example
# import statement with alias name
import math as m
# number
num = 5
# finding factorial
result = m.factorial(num)
# printing factorial
print("Factorial of ", num, " is = ", result)
Output
Factorial of 5 is = 120