- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# Mathematical Constants in Python

In this article, we will go through Python's mathematical constants and how to use them.

Some of the defined constants that can be utilized in a variety of mathematical operations are included in the math module. These mathematical constants return values that are equivalent to their standard defined values.

The following math module constants are available in the Python programming language:

Python math.e constant

Python math.pi constant

Python math.tau constant

Python math.inf constant

Python math.nan constant

## Python math.e constant

The Euler's number, **2.71828182846**, is returned by the math.e constant.

**Syntax**

math.e

**Return Value** − It returns the float value 2.71828182846 which represents the mathematical constant e.

### Example

**Algorithm (Steps)**

Following are the Algorithm/steps to be followed to perform the desired task −

Use the import keyword to import the

**math**module.Print the Euler value

**e**using the e constant of the math module with the help of the (.) operator.

### Example

The following program returns the value of math.e constant using the math module in Python −

# importing math module import math # printing the Euler value e print ("The Euler value e = ", math.e)

### Output

On executing, the above program will generate the following output −

The Euler value e = 2.718281828459045

## Python math.pi constant

The pi value, 3.14159265359, is returned by the math.pi constant. It is described as the ratio of the circumference of a circle to the diameter of a circle.

**Syntax**

math.pi

**Return Value** − It returns the float value **3.14159265359**, which represents the mathematical constant PI.

### Example

**Algorithm (Steps)**

Following are the Algorithm/steps to be followed to perform the desired task −

Use the import keyword to import the

**math**module.Print the

**pi**value using the pi constant of the math module with the help of the (.) operator.

### Example

The following program returns the value of math.pi constant using the math module in Python −

# importing math module import math # printing the pi value print ("The pi value = ", math.pi)

### Output

On executing, the above program will generate the following output −

The pi value = 3.141592653589793

## Python math.tau constant

The **tau** value **6.283185307179586**, is returned by the math.tau constant. It is described as the ratio of the circumference of a circle to the radius of a circle.

**Syntax**

math.tau

**Return Value** − It returns the float value 6.283185307179586, which represents the mathematical constant **tau**.

### Example

**Algorithm (Steps)**

Following are the Algorithm/steps to be followed to perform the desired task −

Use the import keyword to import the

**math**module.Print the

**tau**value using the**tau**constant of the math module with the help of the (.) operator.

### Example

The following program returns the value of math. tau constant using the math module in Python −

# importing math module import math # printing the tau value print ("The tau value = ", math.tau)

### Output

On executing, the above program will generate the following output −

The tau value = 6.283185307179586

## Python math.inf constant

The value of positive infinity is returned by the math.inf constant. Use -math.inf for negative infinity.

The inf constant is the same as float("inf").

**Syntax**

math.inf

**Return Value**: It returns the float value that represents the value of **positive infinity**.

### Example

**Algorithm (Steps)**

Following are the Algorithm/steps to be followed to perform the desired task −

Use the import keyword to import the

**math**module.Print the value of positive infinity using the inf constant of the math module with the help of the (.) operator.

Print the value of negative infinity using the inf constant of the math module with the help of the (.) operator and apply the

**-(negative)**sign to it

### Example

The following program returns the value of math.inf constant using the math module in Python −

# importing math module import math # printing the value of positive infinity print ("The value of positive infinity = ", math.inf) # printing the value of negative infinity print ("The value of negative infinity = ", -math.inf)

### Output

On executing, the above program will generate the following output −

The value of positive infinity = inf The value of negative infinity = -inf

## Python math.nan constant

The floating-point **nan** (Not a Number) value, is returned by the math.nan constant. This is not a valid number. float("nan") is similar to the nan constant.

**Syntax**

math.nan

**Return Value**: It returns the float value, **nan** (Not a Number)

### Example

**Algorithm (Steps)**

Following are the Algorithm/steps to be followed to perform the desired task −

Use the import keyword to import the

**math**module.Print the nan value using the nan constant of the math module with the help of the (.) operator.

### Example

The following program returns the value of math.nan constant using the math module in Python −

# importing math module import math # printing the nan value print ("The nan value = ", math.nan)

### Output

On executing, the above program will generate the following output −

The nan value = nan

### Conclusion

We learned about the mathematical constants available in Python in this article. We also demonstrated how to use these constants in a Python program with some examples.

- Related Articles
- Mathematical Functions in Python - Special Functions and Constants
- PHP Predefined Mathematical Constants
- How can we use various mathematical and physical constants in scipy library?
- Mathematical Functions in Python?
- Python Mathematical Functions
- Mathematical statistics functions in Python
- Mathematical Functions using Python
- Mathematical Functions in Java
- Mathematical Functions in C#
- Mathematical Functions in SQL
- Difference between C++ string constants and character constants
- Decimal constants in C#
- Constants in Rust Programming
- Explain Constants in ES6
- PHP Constants