0% found this document useful (0 votes)
13 views1 page

Python Module Import Basics

The document explains how to use modules in Python, specifically the 'import' and 'from' statements. It provides syntax and examples for both methods, demonstrating how to calculate the square and square root of a number using the 'math' module. The 'from' statement is recommended for importing specific functions to improve efficiency when dealing with large modules.

Uploaded by

darkflux514
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Python Module Import Basics

The document explains how to use modules in Python, specifically the 'import' and 'from' statements. It provides syntax and examples for both methods, demonstrating how to calculate the square and square root of a number using the 'math' module. The 'from' statement is recommended for importing specific functions to improve efficiency when dealing with large modules.

Uploaded by

darkflux514
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer Science

2
import
2
from
Import: It is simplest and most common way to use modules in our code.
Syntax:
import modulename1 [, module name 2, ---------]
Example: Input any number and to find square and square root.
Example:
import math
x = input ("Enter any number")
y = [Link](x)
a = [Link](x,2)
print "Square Root value=",y
print "square value=",a
output:
Enter any number25
Square Root value= 5.0
square value= 625.0
From statement: It is used to get a specific function in the code instead of complete file. If we know
beforehand which function(s), we will be needing, then we may use 'from'. For modules having large
number of functions, it is recommended to use from instead of import.
Syntax
>>> from modulename import functionname [, functionname…..]
from modulename import *
will import everything from the file.
Example: Input any number and to find square and square root.
Example:
from math import sqrt,pow
x=input("Enter any number")
y=sqrt(x) #without using math
a=pow(x,2) #without using math
print "Square Root value =",y
print "square value =",a

You might also like