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

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

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

by Anonymous » 03 Mar 2025, 22:17

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?

Top