# Learn all About Numbers and Mathematical Functions in Python

## Number Data Types in Python

We use number data types in python programming to store and work with numeric values.

There are three main numeric data types in Python:

`Int`

: They are used to represent positive or negative whole numbers with no decimal point. Python 2 has two integer types,`int`

and`long`

, representing small and large integers. However, in Python 3, the`long`

data type was discontinued while the`int`

data type can contain any number size.`Float`

: is a positive a negative number containing one or more decimals. It is often called a Float, or "floating-point number." A float may also be in scientific notation, with E or e indicating the power of 10 (2.5e2 = 2.5 x 10^{2}= 250).`Complex`

: Complex numbers appear as**x + yj**, where**x**is the real part and**y**is the imaginary part.

## How to Assign and Check Number Data Types in Python

In python programming, number data types are automatically created when you assign a value to them.

To check the data type of a variable in python programming, use the `type()`

function.

Example:

```
x = 10
y = 4.90
z = 9j
print(type(x))
print(type(y))
print(type(z))
```

Output:

<class 'int'> <class 'float'> <class 'complex'>

Here are some more examples of number data types:

int | float | complex |
---|---|---|

1 | 0.35 | 45.8j |

1000909290 | 46785.89079938 | 3.14j |

0x920 | 42.6+e12 | 0.123j |

-1234567 | -567.987 | 9.322e-36j |

-0×650 | -71.24e90 | 3e+11J |

In Python programming, you can represent an integer in binary, octal, or hexadecimal form.

```
x = 0o37
y = 0xA0F
z = 0b1101011
print(x)
print(y)
print(z)
print(type(x))
print(type(y))
print(type(z))
```

Output:

2575 31 107 <class 'int'> <class 'int'> <class 'int'>

## How to Convert Number Data Types in Python

In python programming, you can convert from one data type to another using the `int()`

, `float()`

, and `complex()`

functions:

`int(x)`

is used to convert **x** to a plain integer.

`float(x)`

is used to convert **x** to a floating-point number.

`complex(x)`

is used to convert **x** to a complex number with real part **x** and imaginary part zero.

`complex(x, y)`

is used to convert **x** and **y** to a complex number with real part **x** and imaginary part **y** where **x** and **y** are numeric expressions.

Example:

```
x = 989 # int
y = 6.009 # float
z = 88j # complex
# convert from int to float:
a = float(x)
# convert from float to int:
b = int(y)
#convert from int to complex:
c = complex(x)
print(a)
print(b)
print(c)
print(type(a))
print(type(b))
print(type(c))
```

Output:

989.0 6 (88+0j) <class 'float'> <class 'int'> <class 'complex'>

You cannot convert complex data types into another number data type.

- Sikademy Tips

## Mathematical Functions in Python Programming

### Mathematical Constants

There are two main mathematical constants defined in the python module.

Constant | Name | Description |
---|---|---|

e | The number e. | The mathematical natural number e approximately equal to 2.71828 |

pi | The number pi. | The mathematical constant pi approximately equal to 3.14159 |

### Trigonometric Functions

These are functions defined in the python module used to carry out trigonometric calculations.

Function | Name | Description |
---|---|---|

acos(x) | Arc Cosine | This is used to get the arc cosine of a number (x), in radians. |

asin(x) | Arc Sine | This is used to get the arc sine of a number (x), in radians. |

atan(x) | Arc Tangent | This is used to get the arc tangent of a number (x), in radians. |

atan2(y, x) | Arc Tangent | This is used to get the arc tangent in form of atan(y/x), in radians. |

cos(x) | Cosine | This is used to get the cosine of a number (x), in radians. |

hypot(x, y) | Hypotenuse | This is used to get the Euclidean norm, sqrt(x*x + y*y). |

sin(x) | Sine | This is used to get the Sine of a number (x), in radians. |

tan(x) | Tangent | This is used to get the tangent of a number (x), in radians. |

degrees(x) | Degrees | This is used to convert a number (x) to degrees. |

radians(x) | Radians | This is used to convert a number (x) to radians. |

### Mathematical Functions

The following functions are included in Python programming to perform mathematical calculations.

Function | Name | Description |
---|---|---|

abs(x) | Absolute Value | Get the absolute value of x. |

ceil(x) | Ceiling | Get the ceiling of x i.e. the smallest integer not less than x. |

exp(x) | Exponential | Get the exponential of x i.e. e^{x}. |

fabs(x) | Absolute value function | Get the absolute value function of x. |

floor(x) | Floor | Get the floor of x i.e. the largest integer not greater than x. |

log(x) | Natural Log | Get the natural logarithm of x, for x > 0. |

log10(x) | Base-10 Log | Get the base-10 logarithm of x for x > 0. |

max(x1, x2,...) | Maximum Number | Get the largest number of a list of numbers. |

min(x1, x2,...) | Minimum Number | Get the lowest number of a list of numbers. |

modf(x) | Mode | Get the fractional and integer parts of x in a two-item tuple. |

pow(x, y) | Power | Get the value of x to the power of y i.e. x^{y}. |

round(x [,n]) | Round Of | Get x rounded to n digits from the decimal point. |

sqrt(x) | Square Root | Get the square root of x. |

## Wrap Off

Number data types in python programming are used to store and work with numeric values.

There are three main numeric data types in Python: `int`

, `float`

, `complex`

.

If you run into errors or unable to complete this tutorial, feel free to contact us anytime, and we will instantly resolve it. You can also request clarification, download this tutorial as a pdf, or report bugs using the buttons below.