Class 12: Python Math Inbuilt Functions 2

pow(a, b) 

This function is used to compute value of a raised to the power b (a**b).

Example:

import math
print("pow function")
print(math.pow(2,3))
print(math.pow(3,2))

Output:

pow function
8.0
9.0
>>>

sqrt() 

This function returns the square root of the number.

Example:

import math
print("sqrt function")
a=25
print(math.sqrt(a))
a=36
print(math.sqrt(a))

Output:

sqrt function
5.0
6.0
>>>

pi

This is an inbuilt constant that outputs the value of pi(3.141592).

Example:

import math
print("pi value")
print(math.pi)

Output:

pi value
3.141592653589793
>>>

This is an inbuilt constant that outputs the value of e(2.718281).

Example:

import math
print("e value")
print(math.e)

Output:

e value
2.718281828459045
>>>

exp(a) 

This function returns the value of e raised to the power a (e**a)

Example:

import math
print("exp value")
print(math.exp(2))
print(math.exp(3))
print(math.exp(4))

Output:

exp value
7.38905609893065
20.085536923187668
54.598150033144236
>>>