Mathematical Operations in Python: Working with Numbers

thumb_up 1  ·  sell Python math operations, Mathematical calculations in Python, Number manipulation in Python code

Python's standard library provides math module. This module includes many pre-defined functions for performing different mathematical operations. These functions do not work with complex numbers. There is a cmath module contains mathematical functions for complex numbers.

Functions in Math Module

Here is the list of functions available in the math module −

Sr.No Method & Description
1

acos (x)

Return the arc cosine of x, in radians.

2

acosh (x)

Return the inverse hyperbolic cosine of x.

3

asin

Return the arc sine of x, in radians.

4

asinh (x)

Return the inverse hyperbolic sine of x.

5

atan

Return the arc tangent of x, in radians.

6

atan2

Return atan(y/x), in radians.

7

atanh (x)

Return the inverse hyperbolic tangent of x.

8

cbrt (x)

Return the cube root of x.

9

cell(x)

The ceiling of x: the smallest integer not less than x.

10

comb (x,y)

Return the number of ways to choose x items from y iter repetition and without order.

11

copysign(x,y)

Return a float with the magnitude of x but the sign of y.

12

cos (x)

Return the cosine of x radians.

13

cosh (x)

Return the hyperbolic cosine of x.

14

degrees

Converts angle x from radians to degrees.

15

dist (x,y)

Return the Euclidean distance between two points x and y.

16

e

The mathematical constant e = 2.718281..., to available precision.

17

erf (x)

Return the error function at x.

18

erfc (x)

Return the complementary error function at x.

19

exp (x)

Return e raised to the power x, where e = 2.718281...

20

exp2 (x)

Return 2 raised to the power x.

21

expm1 (x)

Return e raised to the power x, minus 1.

22

fabs(x)

The absolute value of x in float

23

factorial(x)

Return x factorial as an Integer.

24

floor (x)

The floor of x: the largest integer not greater than x.

25

fmod (x,y)

Always returns float, similar to x%y

26

frexp (x)

Returns the mantissa and exponent for a given number x.

27

fsum (iterable)

Sum of all numbers in any iterable, returns float.

28

gamma (x)

Return the Gamma function at x..

29

gcd (x,y,z)

Return the greatest common divisor of the specified integer arguments.

30

hypot

Return the Euclidean norm, sqrt(x*x + y*y).

31

inf

A floating-point positive infinity. Equivalent to the output of float('inf").

32

isclose (x,y)

Return True if the values x and y are close to each other and False otherwise.

33

isfinite (x)

Returns True if neither an infinity nor a NaN, and False otherwise.

34

isinf (x)

Return True if x is a positive or negative infinity, and False otherwise.

35

isnan (x)

Return True if x is a NaN (not a number), and False otherwise.

36

isqrt (x)

Return the integer square root of the nonnegative integer x

37

lcm (x1, x2, ..)

Return the least common multiple of the specified integer arguments.

38

ldexp (x,y)

Return x * (2**y). This is the inverse of function frexp().

39

lgamma (x)

Return the natural logarithm of the absolute value of the Gamma function at x.

40

log (x)

Return the natural logarithm of x (to base e).

41

log10 (x)

Return the base-10 logarithm of x.

42

log1p (x)

Return the natural logarithm of 1+x (base e).

43

log2 (x)

Return the base-2 logarithm of x.

44

modf (x)

The fractional and integer parts of x in a two-item tuple. Both parts have the same sign as x. The integer part is returned as a float.

45

nan

A floating-point "not a number" (NaN) value.

46

nextafter (x,y)

Return the next floating-point value after x towards y.

47

perm (x,y)

Return the number of ways to choose x items from y items without repetition and with order.

48

pi

The mathematical constant π = 3.141592..., to available precision.

49

pow (x,y)

Returns x raised to y

50

prod (iterable)

Return the product of all the elements in the input iterable.

51

radians

Converts angle x from degrees to radians.

52

remainder (x,y)

Returns the remainder of x with respect to y

53

sin (x)

Return the sine of x radians.

54

sinh (x)

Return the inverse hyperbolic sine of x.

55

sqrt (x)

Return the square root of x.

56

tan (x)

Return the tangent of x radians.

57

tanh (x)

Return the hyperbolic tangent of x.

58

tau

The mathematical constant τ = 6.283185..., to available precision.

59

trunc (x)

Return x with the fractional part removed, leaving the integer part.

60

ulp

Return the value of the least significant bit of the float x.

These functions can be classified in following categories −

 

 

The End! should you have any inquiries, we encourage you to reach out to the Vercaa Support Center without hesitation.

Was this answer helpful?

Related Articles

description

Exploring Python's Key Characteristic

Python is a feature rich high-level, interpreted, interactive and object-oriented scripting language. This tutorial will list down some of…

arrow_forward
description

Comparing Python and C++

Both Python and C++ are among the most popular programming languages. Both of them have their advantages and disadvantages. In this…

arrow_forward
description

Creating a Python Hello World Program

This tutorial will teach you how to write a simple Hello World program using Python Programming language. This program will make use of…

arrow_forward
description

Python's Versatile Application Domains

Python is a general-purpose programming language. It is suitable for development of wide range of software applications. Over last few…

arrow_forward
description

Understanding the Python Interpreter

Python is an interpreter-based language. In a Linux system, Python's executable is installed in /usr/bin/ directory. For Windows, the…

arrow_forward
arrow_back « Back