Import Statement
The syntax of import statement is as follows:
This gives us access to all the functions in the module(s).
The syntax is as shown below:
Python library has many built-in modules that are really handy to programmers. Let us explore some commonly used modules and the frequently used functions that are found in those modules:
1. Module name : math
import math
Some of the commonly used functions in math module are given in Table.
2. Module name : random
import random
3. Module name : statistics
import statistics
Important points regarding Import Statement:
From Statement
Its syntax is :
from modulename import functionname [,functionname,…]
Example-
Output:
Example –
Output:
Composition
Example :
a = int(input("First number: "))
print("Square root of ",a ," = ",math.sqrt(a))
print(floor(a+(b/c)))
math.sin(float(h)/float(c))
Create a user defined module basic_math that contains the following user defined functions:
The requirement is:
Output:
doc variable stores the docstring. To display docstring of a module we need to import the module and type the following:
print(<modulename>._ _doc_ _) #_ _ are 2 underscore without space
20 videos|20 docs|5 tests
|
|
Explore Courses for Humanities/Arts exam
|