# Python Number Data types

## Overview

Python Number data types represent numeric data that are useful for performing mathematical and scientific calculations.

Integers, floating point numbers, and complex numbers fall under the Python number category.

## Python Number Data types

Python has several numerical data types that are used to represent numbers. These include:

Number Datatype |
Description |

int |
The int datatype represents whole numbers. It supports signed integer values, both positive and negative.
Examples: 9, -73, 326, etc. |

float |
The float datatype represents real numbers, i.e., floating point real values. (numbers with fractional parts).
Examples: 3.14, -0.007, 21.65, etc. |

long |
The long data type supports long integers that can be represented in octal and hexadecimal. In Python 3, we can use only the int type.
In Python 2, the long data type was used to represent numbers that were too large for the int data type. However, in Python 3, this distinction was removed, and only the int data type remains. You no longer need to worry about whether a number is too large and needs to be represented as a long data type. In Python 3, the int data type has no limit to its size, apart from the available memory. |

complex |
The complex datatype represents complex numbers. A complex number consists of a real part and an imaginary part. Complex numbers are written as a, where +bja represents the real part and b represents the imaginary part.
Examples: 7 + 9j, -3 – 5j. |

The function *type*() can be used to determine which class a variable or a value belongs to, and the function *instance*() is used to check if an object belongs to a particular class.

Integers can be of any length and are limited by the memory available. A floating point number is accurate up to 15 decimal places.

## Examples

Illustration of number data type. The creation of number variables illustrated in interactive mode as below:

*>>> i = 1234 # i holds the integer 1234*

*>>> i*

*1234*

*>>>*

*>>> pi = 3.14 # pi holds the value 3.14*

*>>> pi*

*3.14*

*>>> 2 * pi*

*6.28*

*>>> clx = 7 + 9j # complex number*

*>>> clx*

*(7+9j)*

*>>> # Python Number Data Types – www.TestingDocs.com*

*>>>*

Python supports various mathematical operations on these data types, such as addition, subtraction, multiplication, division, etc. It automatically handles conversions between these types during arithmetic operations, like promoting an int to a float in an operation involving both types.

—

## Python Tutorials

Python Tutorial on this website can be found at:

https://www.testingdocs.com/python-tutorials/

Official Website

More Information on Python: