Python Numeric Data Types

Python Numeric Data Types


Numeric data types are numbers stored in the memory. You can perform operations such as addition, subtraction, multiplication, division, modulo, etc on numeric data. The following data types can be categorized as numeric types.

  • int
  • float
  • complex

Integer type

Integers are the whole numbers means there are no floating-point values in them. A variable of integer type is created when you assign an integer value to the variable. In Python, integers can be of any length, it is only constrained by the amount of memory your system has.

Examples of integers

0, 2, -5, 100, 852200

Examples of non-integers

0.2, 8.1, 2*5.1, 2j

Float type

These numbers are specified by a decimal point. A variable of the float type is created when you assign a float value to the variable. A number that is expressed with e or E character is also float type.

Usually, all the platforms represent float values with 64-bit double-precision values. The maximum value that a float variable can have is approximately 1.8e308, a value greater than this is represented by the string inf in Python.

You can see this in the image below –

Examples of float type

5.4, 0.2, 2/3, -0.000111, 12e8, 3E34

Complex type

Complex numbers are written in the form of a+bj where a is real part and bj is the imaginary part.

Examples of complex type

2+3j, 5j, -2.7j

Example of Python numeric type of data

A variable of type int, float, or complex is created when you assign a numeric value to it. Now see the given example that shows the usage of different data types i.e. int, float, and complex in Python.

x=2   # x contains integer value
y=3.5 # y contains float value
z=-3.1j # z contains complex number

Since data types are classes and the variables are instances of those classes in Python now the output will display the class name that you can see in the image below –

Next, we will learn the boolean data type in Python along with some examples.

Previous Data Types in Python
Next Python Boolean Data Type

About author

You might also like

Programming 0 Comments

Python List Data Type

The list data type is exclusively used in Python. You can use this to store multiple values in a single variable. This data type is very similar to array in

Python Programming 0 Comments

Python Indentation

An indentation or indent is an empty space at the beginning of a line that signals the start of a new logical block in a Python program. Many programming languages

Programming 0 Comments

Python List Comprehension

A python list can hold multiple different types of values in a single variable. In our previous article on Python list data type, we had discussed the Python lists, how


No Comments Yet!

You can be first to comment this post!

Leave a Reply