Page 1 of 1

Warum meldet Sys.getSizeof () für zwei Instanzen die gleiche Größe, obwohl man ein zusätzliches Attribut hat?

Posted: 03 Mar 2025, 22:17
by Anonymous

Code: Select all

import sys

class MyObject:
def __init__(self,name,salary):
self.name = name
self.salary = salary

obj1 = MyObject("Tushar", 50)
obj2 = MyObject("Tushar", 50)
obj2.age = 20

print(sys.getsizeof(obj1))  # 56
print(sys.getsizeof(obj2))  # 56
Warum ist OBJ2 nur 56 Bytes, wenn es ein zusätzliches Alter Attribut hat?