Constants of Maths in Python

Math module is a standard in-built module in Python that can be used for performing the mathematical tasks. The math module has a set of methods and constants.

Note: For more information, refer to Math-library-functions

1. Python math.e constant: The math.e constant returns the Euler’s number: 2.71828182846.

Syntax: math.e

Returns: Return a float value, 2.71828182846, representing the mathematical constant e



Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import math Library
import math
  
# Print the value of Euler e
print (math.e)

chevron_right


Output:

2.718281828459045

2. Python math.pi constant: The math.pi constant returns the value pi: 3.14159265359. It is defined as the ratio of the circumference to the diameter of a circle.

Syntax: math.pi

Returns: A float value, 3.14159265359, representing the mathematical constant PI

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import math Library
import math
  
# Print the value of pi
print (math.pi)

chevron_right


Output:

3.141592653589793

3. Python math.tau constant: The math.tau constant returns the value tau: 6.283185307179586. It is defined as the ratio of the circumference to the radius of a circle.



Syntax: math.tau

Returns: A float value, 6.283185307179586, representing the mathematical constant tau

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import math Library
import math
  
# Print the value of tau
print (math.tau)

chevron_right


Output:

6.283185307179586

4. Python math.inf constant: The math.inf constant returns of positive infinity.
For negative infinity, use -math.inf.The inf constant is equivalent to float(“inf”).

Syntax: math.inf

Returns: A float value, returns the value of positive infinity.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import math Library
import math
  
# Print the positive infinity
print (math.inf)
  
# Print the negative infinity
print (-math.inf)

chevron_right


Output:

inf
-inf

5. Python math.nan constant: The math.nan constant returns a floating-point nan (Not a Number) value. This value is not a legal number.The nan constant is equivalent to float(“nan”).

Syntax: math.nan

Returns: A float value, nan (Not a Number)

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Import math Library
import math
  
# Print the value of nan
print (math.nan)

chevron_right


Output:

nan



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.