[Tutor] Python Memory Allocation -- deep learning
Sunil Tech
sunil.techspk at gmail.com
Mon Jul 30 09:20:59 EDT 2018
Hi Team,
I am investigating how the memory allocation happens in Python
For Eg:
*Case 1:*
>>> a = 10
>>> b = 10
>>> c = 10
>>> id(a), id(b), id(c)
(140621897573616, 140621897573616, 140621897573616)
>>> a += 1
>>> id(a)
140621897573592
*Case 2:*
>>> x = 500
>>> y = 500
>>> id(x)
4338740848
>>> id(y)
4338741040
*Case 3:*
>>> s1 = 'hello'
>>> s2 = 'hello'
>>> id(s1), id(s2)
(4454725888, 4454725888)
>>> s1 == s2
True
>>> s1 is s2
True
>>> s3 = 'hello, world!'
>>> s4 = 'hello, world!'
>>> id(s3), id(s4)
(4454721608, 4454721664)
>>> s3 == s4
True
>>> s3 is s4
False
Python memory allocation is varying in all these use cases. Please help me
understand.
Thanks,
Sunil. G
More information about the Tutor
mailing list