3
class A():
    def __init__(self):
        self.a = 1
        self.b = 2

a = A()
a.zzz = 2

b = int()
b.zzz = 2
Traceback (most recent call last):
  File "/home/user/test.py", line 10, in <module>
    b.zzz = 2
AttributeError: 'int' object has no attribute 'zzz'

I don't understand the difference between the class I defined and the int class, why can a custom class add a new attribute, and the original int cannot.

sim
  • 73
  • 5

0 Answers0