# Python numbers

Number inPythonIt can be of 3 types:`int`,`float`with`complex`.

### Integer

For integers`int`class. You can use value literals to define integers:

``age = 8``

You can also use`int()`Constructor:

``age = int(8)``

Check if the variable is of type`int`,you can use it`type()`Global functions:

``type(age) == int #True``

### Floating point number

Floating point numbers (fractions) are types`float`. You can use value literals to define integers:

``fraction = 0.1``

Or use`float()`Constructor:

``fraction = float(0.1)``

Check if the variable is of type`float`,you can use it`type()`Global functions:

``type(fraction) == float #True``

### plural

The plural is the type`complex`.

You can use value literals to define them:

``complexNumber = 2+3j``

Or use`complex()`Constructor:

``complexNumber = complex(2, 3)``

Once you have a complex number, you can get the real and imaginary parts:

``````complexNumber.real #2.0
complexNumber.imag #3.0``````

Similarly, check if the variable is of type`complex`,you can use it`type()`Global functions:

``type(complexNumber) == complex #True``

### Arithmetic operations of numbers

You can use arithmetic operators to perform arithmetic operations on numbers:`+`,`-`,`*`,`/`(distribution),`%`(More than),`**`(Exponentiation) and`//`(Floor division):

``````1 + 1 #2
2 - 1 #1
2 * 2 #4
4 / 2 #2
4 % 3 #1
4 ** 2 #16
4 // 2 #2``````

You can use the compound assignment operator

• `+=`
• `-=`
• `*=`
• `/=`
• `%=`
• ..and many more

You can also quickly perform operations on variables:

``````age = 8
age += 1``````

### Built-in function

There are 2 built-in functions to help numbers:

`abs()`Returns the absolute value of the number.

`round()`Given a number, round its value to the nearest integer:

``round(0.12) #0``

You can specify the second parameter to set the decimal point precision:

``round(0.12, 1) #0.1``

The Python standard library provides several other mathematical utility functions and constants:

• This`math`The package provides regular mathematical functions and constants
• This`cmath`The software package provides utilities to handle complex numbers.
• This`decimal`The software package provides utilities for using decimal and floating-point numbers.
• This`fractions`The package provides utilities to use rational numbers

We will discuss some of them separately later.