Introduction
What is Module?
In C and C++ Programming we have header files, in which we can have functions, class variables, etc. By including that header files in our code we don't write more code and reuse our functions. Same as in Python we have modules, which may have functions, classes, variables and compiled code. A module contains a group of related functions, classes, and variables.
There are three kinds of modules in python:
- Modules are written in Python(.py).
- Modules which are written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc).
- Modules that are written in C but linked with an interpreter to get the list of all modules which are written in C, but linked with Python you can use the following code.
Output:
- import sys
- print(sys.builtin_module_names)
('_ast', '_bisect', '_codecs', '_codecs_cn', '_codecs_hk', '_codecs_iso2022', '_codecs_jp', '_codecs_kr', '_codecs_tw', '_collections', '_csv', '_datetime', '_functools', '_heapq', '_imp', '_io', '_json', '_locale', '_lsprof', '_md5', '_multibytecodec', '_opcode', '_operator', '_pickle', '_random', '_sha1', '_sha256', '_sha512', '_sre', '_stat', '_string', '_struct', '_symtable', '_thread', '_tracemalloc', '_warnings', '_weakref', '_winapi', 'array', 'atexit', 'audioop', 'binascii', 'builtins', 'cmath', 'errno', 'faulthandler', 'gc', 'itertools', 'marshal', 'math', 'mmap', 'msvcrt', 'nt', 'parser', 'signal', 'sys', 'time', 'winreg', 'xxsubtype', 'zipimport', 'zlib').
Python Math Module
Ceil and floor function
Ceil and floor functions are common functions. The ceil function rounds up the number to the next highest one. The floor function removes digits decimal points. Both functions take a decimal number as argument and return an integer.
Example:
- #Importing math Module
- import math
- #Fractional number
- number=8.10
- #printing ceiling value of the fractional number
- print("Ceiling value of 8.10 is :",math.ceil(number))
- #printing floor value of the fractional number
- print("Floor value of 8.10 is :",math.floor(number))
Output:![]()
fabs function
fabs function is used to compute the absolute value of any number. If a number contains any negative(-) sign, then it removes that sign and returns a positive fractional number.
Example:Output:
- #Importing math Module
- import math
- number = -8.10
- #printing absolute value of the number
- print(math.fabs(number))
![]()
factorial function
This function takes a positive integer number and prints factorial of that number.
Example:
- #Importing math Module
- import math
- number = -8.10
- #printing absolute value of the number
- print(math.fabs(number))
Output:
Note: When you will enter negative number, then you will get a Value Error.Example:Output:
- #Importing math Module
- import math
- number = -5
- #printing factorial of the number
- print("fatorial of the number is",math.factorial(number))
![]()
fmod function
function fmod(x,y) returns x%y. But the difference is x%y preferred when working with integers fmod(x,y) and is used when working with floats.
Example:Output:
- #Importing math Module
- import math
- print(math.fmod(5,2))
- print(math.fmod(-5,2))
- print(math.fmod(-5.2,2))
- print(math.fmod(5.2,2))
![]()
frexp function
This function returns mantissa and exponent in the pair(m,n) of any number x by solving the following equation.
Example:
Output:
- #Importing math Module
- import math
- print(math.frexp(24.8))

fsum function
It calculates accurate floating-point sum of values in iterable and calculates the sum of the list of data or range of data.
Example:Output:
- #Importing math Module
- import math
- #sum of list of data
- numbers=[.1,.2,.3,.4,.5,.6,.7,.8,8.9]
- print("sum of ",numbers," is :",math.fsum(numbers))
- #sum of range
- print("sum of 1 to 10 numbers is :",math.fsum(range(1,11)))
![]()
Power and Logarithmic Function
exp function
This function takes one parameter as a fractional number and returns e^x.
Example:
- #Importing math Module
- import math
- print("e ^ 5 is ",math.exp(5))
- print("e ^ 2.5 is",math.exp(2.5))
Output:
expm1 function
This function works same like exp function but returns exp(x)-1. Here expm1 means exp-m-1 that is exp-minus-1.


Santhakumar MunuswamyPosted Oct 18, 2015, 4:05 AM
Good one
Harshad PansuriyaPosted Oct 10, 2015, 8:22 AM
Nice one
Nilesh JadavPosted Oct 10, 2015, 7:51 AM
Nice work sir