Number data types store numeric values. Number objects are created when you assign a value to them. For example:
var1 = 1 # variable declare with value 1 var2 = 5 # variable declare with value 5 a=10 # variable declare with value 10 print (id(a)) # print variable memory id print (type(a)) # print data type of 'a' variable import sys a=10 #can grow memory size according to value. a = sys.getsizeof(12) #get data type size print(a) #print size:
You can also delete the reference to a number object by using the del statement. The syntax of the del statement is:
var1 = 1 var2 = 10 del var1 print(var2)
Python supports three different numerical data types:
All integers in Python3 are represented as long integers. Hence, there is no separate number type as long.
A float number is represented as decimal value
n = 10.5 # float data type
A complex number consists of an ordered pair of real floating-point numbers denoted by x + yj, where x and y are real numbers and j is the imaginary unit.
n = 6+9j # Complex Data type
In Python 2, the result of division of two integers is rounded to the nearest integer. As a result, 3/2 will show 1. In order to obtain a floating-point division, numerator or denominator must be explicitly used as float. Hence, either 3.0/2 or 3/2.0 or 3.0/2.0 will result in 1.5
Python 3 evaluates 3 / 2 as 1.5 by default, which is easier for new programmers.