Lis le code attentivement
class Point:
__slots__ = ("x", "y")
def __init__(self, x, y):
self.x = x
self.y = y
class Tagged(Point):
pass
p = Point(1, 2)
t = Tagged(3, 4)
print(f"p:{p.x},{p.y}")
print(f"t:{t.x},{t.y}")
print(hasattr(p, "__dict__"))
print(hasattr(t, "__dict__"))
try:
p.z = 99
print(f"p.z={p.z}")
except AttributeError:
print("p:no_z")
t.z = 99
print(f"t.z={t.z}")
Que va afficher le programme ? Écris ici :