EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Python 3 Tutorial Python 3 math module
Secondary Sidebar
file_put_contents in PHP

is_array in PHP

Introduction to Python

Python Competitive Programming

Java NIO SocketChannel

Python Books

Python 3 math module

Python 3 math module

Definition of python 3 math module

Python 3 math module complex data types aren’t supported by this module. The cmath module is the more complicated sibling. When working on financial or scientific tasks, it is sometimes important to use mathematical calculations. Python has a math module that may be used to perform such computations. In Python, the math module is a standard module that is always available. To utilize the mathematical functions provided by this module.

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,883 ratings)

Overview of Python 3 math module

  • The mathematical functions defined by the C standard are accessible through this module. If we need support for complex numbers, use the cmath module’s functions with the same name.
  • Because most users do not wish to study nearly as much mathematics as is required to understand complex numbers, a differentiation between functions that support complex numbers and those that do not is made.
  • Receiving an exception rather than a complex result allows the programmer to discover the unexpected complex number supplied as a parameter earlier.
  • Addition (+), subtraction (-), multiplication (*), division (/), and advanced operations such as trigonometric, logarithmic, and exponential functions are all covered by the Math module.
  • The values of several constants such as pi are provided by the math module. Having such constants saves time since we don’t have to write the value of each constant every time we wish to use it, and we can do it with more precision.
  • The math module defines some of the most often used mathematical functions. These include trigonometric, representation, logarithmic, and angle conversion functions, among others.
  • The angle in radians is required as an argument for the functions (sin, cos, tan, and so on). In contrast, we are accustomed to expressing angles in degrees. To convert an angle from degrees to radians and vice versa, the math module provides two angle conversion functions degrees and radians.
  • It also specifies two mathematical constants, namely Pie and Euler number, among others.
  • In Python, the math module is used to perform calculations. Exponential, logarithmic, and trigonometric functions are among the many sophisticated mathematical operations covered.
  • As result, the math module will come in handy for financial, scientific, and math-related applications.
  • The ratio of circumstance to the diameter of a circle is defined as Pie (n), a well-known mathematical constant. 3.14 is its value.
  • A built-in Python library is the math module. It is useful for a variety of C-based mathematical functions.
  • The Python math module, which is efficient and fast, relies on mathematical functions specified by the C standard.

How to use python 3 math module?

Math is a built-in standard module in Python that is used to do complicated scientific computations.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

So, if we want to use mathematical functions in the math module to evaluate sophisticated mathematical operations like trigonometric operations, logarithmic operations, and so on, we need use Python math functions.

The natural logarithm of an integer is returned by the logarithmic function. After raising a preset value, the exponential function returns a float number. Returns the square root of a given number using the square root function.

Below is the most used python functions are as follows.

1. Fabs(x) – It returns the absolute value of x.

2. Ceil() – It returns the smallest integer higher or equal to x.

3. Floor() – It returns the largest integer less than or equal to x.

4. Factorial() – It returns the factorial of x.

5. Gcd() – It returns the gcd of x. This function is used to find the greatest common divisor of two numbers.

  • To utilize the Math module in our Python program, we must first import it using import math instructions. After that, we can use any of the module’s methods. Some mathematical calculations may be performed with simplicity in Python using the math module.
  • Complex data types aren’t supported by the math module. We can use the cmath module as the complex counterpart for this.

Below example shows the use of the math module in python 3 are as follows.

Code:

import math
data = 34.6
print ('Floor of 34.6 is', math.floor (data))

Output:

Python 3 math module output 1

In the below example, we are checking the value of PI using math.pi function is as follows.

Code:

import math
print('Value of PI is:',math.pi)

Output:

Check value of PI

  • The math module offers functions for calculating various trigonometric ratios. The angle in radians is required as an argument by the functions (sin, cos, tan, etc.).
  • In contrast, we are accustomed to expressing the angle in degrees. The angle conversion functions degrees and radians in the math module convert angles from degrees to radians and vice versa.

The below example shows the use of the power module in python 3 is as follows.

Code:

import math
print (math.pow (5, 7))

Output:

Use of power module

  • The ceil function produces the lowest integer value that is greater than the given value. If the number is already an integer, it will be returned with the same value.
  • Ceil produces the lowest integer that is not less than x – the ceiling value of x. The below example shows the use of the python ceil function is as follows.

Code:

import math
data = 23.5
print (math.ceil (23.5))

Output:

Use of python ceil function

Python 3 math module Examples

The below example shows an example of the python 3 math module is as follows.

Example #1

In the below example, we have used atan, pow, and pi functions to show the output.

Code:

import math
print (math.atan (50))
print (math.pow (4,3))
print (math.pi)

Output:

Python 3 math module Example 1

Example #2

The below example shows the use of basic functions in python 3 is as follows. In the below example, we have used ceil and factorial functions.

Code:

import math
print (math.ceil (20.44))
print (math.factorial (6))

Output:

Python 3 math module Example 2

Example #3

The below example shows the use of trigonometric function in the python 3 math module is as follows.

Code:

import math
angleInDegree = 120
angleInRadian = math.radians (angleInDegree)
print('Angle is :', angleInRadian)
print('sin value is :', math.sin (angleInRadian))
print('cos value is :', math.cos (angleInRadian))
print('tan value is :', math.tan (angleInRadian))

Output:

Python 3 math module Example 3

Conclusion

In Python, the math module is used to perform calculations. Exponential, logarithmic, and trigonometric functions are among the many sophisticated mathematical operations covered. As result, the math module will come in handy for financial, scientific, and math-related applications. Python 3 math module complex data types not supported by this module.

Recommended Articles

This is a guide to Python 3 math module. Here we discuss the definition, overviews; How to use python 3 math module, Examples with code implementation. You may also have a look at the following articles to learn more –

  1. Python Int to String
  2. Python Add List
  3. Python String to Float
  4. Python Timeit
Popular Course in this category
Python Certifications Training Program (40 Courses, 13+ Projects)
  40 Online Courses |  13 Hands-on Projects |  215+ Hours |  Verifiable Certificate of Completion
4.8
Price

View Course
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more