Python

Data Types
import sys
import cmath
import math

Numeric Data Types

Integers

a=10
b=20
c=30
print(“a=%d address=%d type=%s” %(a,id(a),type(a)))
print(“b=%d address=%d type=%s” %(b,id(b),type(b)))
print(“c=%d address=%d type=%s” %(c,id(c),type(c)))

Output:

a=10 address=10914784 type=
b=20 address=10915104 type=
c=30 address=10915424 type=

integer size can be dynamic

a = 12345678
b = 1234567898726512
c = 9283787182749827498
print(“a = %d address=%d type=%s size=%d”%(a,id(a),type(a),sys.getsizeof(a)))
print(“b = %d address=%d type=%s size=%d”%(b,id(b),type(b),sys.getsizeof(b)))
print(“c = %d address=%d type=%s size=%d”%(c,id(c),type(c),sys.getsizeof(c)))

a = 12345678 address=140126022940752 type= size=28
b = 1234567898726512 address=140126022940112 type= size=32
c = 9283787182749827498 address=140126022314704 type= size=36

Integer Pooling

To fasten allocation and de-allocation of memory to ingeters, python uses dedicated memorypool for integers between -5 to +256.

when integer values are diff the memory allocation is also diff


a=10
b=12
c=14
print(“a=%d address=%d type=%s”%(a,id(a),type(a)))
print(“b=%d address=%d type=%s”%(b,id(b),type(b)))
print(“c=%d address=%d type=%s”%(c,id(c),type(c)))

When we have same data, with in (-5 to -256) then we do get same address

d=100
e=100
f=1020
g=1020
print(“d=%d address=%d type=%s”%(d,id(d),type(d)))
print(“e=%d address=%d type=%s”%(e,id(e),type(e)))
print(“f=%d address=%d type=%s”%(f,id(f),type(f)))
print(“g=%d address=%d type=%s”%(g,id(g),type(g)))

a=10 address=10914784 type=
b=12 address=10914848 type=
c=14 address=10914912 type=
d=100 address=10917664 type=
e=100 address=10917664 type=
f=1020 address=140126022940560 type=
g=1020 address=140126022939504 type=

You missed