Python math module

The math module in Python is used to perform mathematical tasks, with functions, including, trigonometric, logarithmic, etc.

How to import the math module

To import the math module and use its mathematical functions, write the following at the start of the Python program:

Examples – math module functions

Let us see the following examples of the math module:

  1. sqrt()
  2. ceil()
  3. floor()
  4. pow()
  5. fabs()
  6. factorial()
  7. sin()
  8. cos()
  9. tan()
  10. log()

sqrt() function in Python

To return the square root of a number, use the sqrt() function in Python. Let us see an example:

The output is as follows:

ceil() function in Python

To round a number up to the nearest integer, use the ceil() function in Python. Let us see an example:

The output is as follows:

floor() function in Python

To round a number down to the nearest integer number, use the floor() function in Python. Let us see an example:

The output is as follows:

pow() function in Python

To return the value of p to the power of q, use the pow() function in Python. Let us see an example:

The output is as follows:

fabs() function in Python

To return the absolute value of a number, use the fabs() function in Python. The value returned is a float. Let us see an example:

The output is as follows:

factorial() function in Python

To return the factorial of a number, use the factorial() function in Python. Let us see an example:

The output is as follows:

sin() function in Python

To return the sin of a number, use the sin() function in Python. Let us see an example:

The output is as follows:

cos() function in Python

To return the cosine of a number, use the cos() function in Python. Let us see an example:

The output is as follows:

tan() function in Python

To return the tangent of a number, use the tan() function in Python. Let us see an example:

The output is as follows:

log() function in Python

To return the logarithm of a number, use the log() function in Python. Let us see an example:

The output is as follows:

Python Tutorial (English)

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

Python statistics module
Python random module
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading