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
print(type(x))
print(type(y))
print(type(z))

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

Python Programming 0 Comments

Escape sequences in Python

An escape sequence or escape character allows you to insert a special character in a string. For example, you can insert a new line in a string using \n character.

Programming 0 Comments

Python Boolean Data Type

Boolean or bool is a built-in data type in the python programming language. It can have two possible values –   True  False These are equivalent to 1 and 0

Python Programming 0 Comments

Setup Python Development Environment With VS Code In Linux

Visual studio code (VS Code) is a free and open-source IDE that is developed by Microsoft. It is a lightweight IDE that has powerful features like smart code completion, code

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply