Introduction

Setup

Operators

variable

String

Number

Dtype & Comment

Lists

Tuples

Sets

Dictionaries

if else statement

For Loop

While Loop

iterator & iterable

Pre-Built functions

Function

Decorators

Generators

Types of errors

Exceptions Handling

OOP

Regular expression

Create module

OS module

Date module

Random module

Math

Statistics module

Exercise 1

Exercise 2

Exercise 3

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Learn Matplotlib

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

Learn MySQL

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

Python math module

What is math module?

Python has a built-in math module. By this math module you can perform various mathematical task.

Math module methods:


Methods Description
math.copysign() This function returns a float consisting of the value of the first parameter and the sign of the second parameter
math.cos() This function returns the cosine of a number
math.cosh() This method returns the hyperbolic cosine of a number
math.atan() This method returns the arc tangent of a number in radians
math.atan2() This method returns the arc tangent of y/x in radians
math.atanh() This method returns the inverse hyperbolic tangent of a number
math.ceil() This method is use to rounds up a number to the nearest integer
math.dist() This method returns the Euclidean distance between two points (a and z). Here a and z are the coordinates of that point
math.erf() This method returns the error function of a number
math.erfc() This function the complementary error function of a number
math.exp() This function returns R raised to the power of x
math.expm1() This function returns Ex - 1
math.comb() This method returns the number of ways to choose j items from n items without repetition and order
math.acos() This method returns the arc cosine of a number
math.acosh() This method returns the inverse hyperbolic cosine of a number
math.asin() This methods returns the arc sine of a number
math.asinh() This method returns the inverse hyperbolic sine of a number
math.asinh() This method returns the inverse hyperbolic sine of a number
math.degrees() This method is used to converts an angle from radians to degrees
math.fabs() This function returns the absolute value of a number
math.factorial() This method returns the factorial of a number
math.floor() This method is used to rounds down a number to the nearest integer
math.fmod() This method returns the remainder of x/y
math.frexp() This method returns the mantissa and the exponent, of a specified number
math.fsum() This method returns the sum of all items in any iterable
math.gamma() This method returns the gamma function at x
math.gcd() This method returns the greatest common divisor of two integers
math.hypot() This method returns the Euclidean norm
math.isclose() This method checks whether two values are close to each other, or not
math.isfinite() This method checks whether a number is finite or not
math.isinf() This method checks whether a number is infinite or not
math.isnan() This method checks whether a value is NaN (not a number) or not
math.isqrt() this method rounds a square root number downwards to the nearest integer
math.ldexp() This method returns the inverse of math.frexp()
math.lgamma() This method returns the log gamma value of x
math.sin() This method returns the sine of a number
math.sinh() This method returns the hyperbolic sine of a number
math.sqrt() This method returns the square root of a number
math.tan() This method returns the tangent of a number
math.tanh() This method returns the hyperbolic tangent of a number
math.trunc() This method returns the truncated integer parts of a number
math.log() This method returns the logarithm of number to base
math.log10() This method returns the base-10 logarithm of x
math.log1p() This method returns the natural logarithm of 1+x
math.perm() This method returns the number of ways to choose k items from n items with order and without repetition
math.log2() This method returns the base-2 logarithm of x
math.pow() This method returns the value of x to the power of y
math.prod() This method returns the product of all the elements in an iterable
math.remainder() This returns the closest value that can make numerator completely divisible by the denominator
math.radians() This method converts a degree value into radians


Math module constants

Methods Description
math.inf This method returns a floating-point positive infinity
math.nan This method returns a floating-point NaN (Not a Number) value
math.e This method returns Euler's number
math.tau This method returns tau
math.pi This method returns PI

Example:1
Input
import math

print(math.asin(0.75))
print(math.asin(-0.75))

print (math.cos(2.00))
print (math.cos(-1.73))

print(math.log(2.7773))
print(math.log(4))

print (math.sin(1.10))
print (math.sin(-2.33))
Output
0.5823642378687435
-0.5823642378687435

-0.4161468365471424
-0.15853200064419776

1.021479232738285
1.3862943611198906

0.8912073600614354
-0.7253843874668195
Example:2
Input
import math

print (math.e)

print (math.pi)

print (math.tau)
Output
2.718281828459045

3.141592653589793

6.283185307179586

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.