×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python as Keyword

By IncludeHelp Last updated : December 07, 2024

Description and Usage

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

Syntax of as keyword:

import module_name as alias_name

Sample Input/Output

Import statement:
import math as m

# function call
m.factorial(5)

Output:
120

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

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.