Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
110 views

Import Module in Python

Import in Python allows code to access functions and variables from other modules. The import statement searches for the module locally by calling the __import__() function, and returns its value. Common ways to import include importing the entire module using import module_name, importing specific items using from module import item1, item2, or importing everything using from module import *. This allows accessing functions and variables directly or through the module without having to specify the module name.

Uploaded by

Anoop A S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views

Import Module in Python

Import in Python allows code to access functions and variables from other modules. The import statement searches for the module locally by calling the __import__() function, and returns its value. Common ways to import include importing the entire module using import module_name, importing specific items using from module import item1, item2, or importing everything using from module import *. This allows accessing functions and variables directly or through the module without having to specify the module name.

Uploaded by

Anoop A S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Import module in Python

Import in python is similar to #include header_file in C/C++. Python modules can get access to
code from another module by importing the file/function using import. The import statement is
the most common way of invoking the import machinery, but it is not the only way.

import module_name
When the import is used, it searches for the module initially in the local scope by calling
__import__() function. The value returned by the function is then reflected in the output of the
initial code.

Program 1

import math
print(math.pi)

Output:
3.141592653589793

Program 2

from math import pi


# Note that in the above example,
# we used math.pi. Here we have used
# pi directly.
print(pi)

Output:
3.141592653589793

Program 3

from math import *


print(pi)
print(factorial(6))

Output:
3.141592653589793
720

You might also like