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