When you create a user-defined class, you can, by default, dinamically add attributes to it just like in the next example:
# User defined class
class Test:
def __init__(self):
self.first_att = 5
test = Test()
test.second_att = 11
print(test.__dict__)
{'first_att': 5, 'second_att': 11}
But built-in classes don't allow such a thing:
# Built-in class
str_example = 'Test string'
str_example.added_att = 5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'added_att'
How can I modify my class Test so it doesn't allow it also? Thanks in advance