size of an object | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

size of an object

https://code.sololearn.com/c4Zhhx62Fu32/#py why in both case am i getting the same space allocated ??. Shouldn't it be different ?? or did I understood it wrong??. Do explain??

21st Jul 2020, 6:47 AM
Mani
Mani - avatar
3 Answers
+ 2
Mani 2 objects with non-overlapping lifetime can have same Id.
21st Jul 2020, 6:52 AM
Arsenic
Arsenic - avatar
+ 2
you are assigning two variables to the class itself. that is why the values turn out the same. instead you should assign the object of the class like this c1 = computer() c2 = computer() so that the values would be different since it is a separate object from each other.
21st Jul 2020, 9:16 AM
Shen Bapiro
Shen Bapiro - avatar
+ 1
Hi, Python id() function returns an identity of an object. This is an integer which is guaranteed to be unique. This function takes an argument an object and returns a unique integer number which represents identity. As arsensic told" Two objects with non-overlapping lifetimes may have the same id() value". For more reference : https://www.geeksforgeeks.org/id-function-python/
21st Jul 2020, 7:41 AM
AjayGohil