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

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

Post 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?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post