Why does python allow to make different set of attributes for same class?

oop, python

Solution

Because Python is a dynamic language. A Python object is mostly a dict (containing instance attributes) + a reference to base classes (which are objects too) + a couple hooks looking class attributes on the base classes when they don't exist in the instance's dict. FWIW you can even change an object's type at runtime if you want.

How does it helps design code ? Well, having the ability to dynamically add / replace arbitrary instance and class attributes (including methods) at runtime makes life much much easier for some kind of problems.

Problem

I just started python, in java two different instances of same type have different values but it doesn't allow them to have different attributes. But, ``` class Point: pass p1 = Point() p1.x = 0 p1.y = 0 p2 = Point() p2.z = 0 p2.w = 1355135 ``` This code doesn't produce any error. So i am assuming it is a language feature. But i don't understand why python allows two instances of same type have different attributes? How does it help in designing code?

Original source