are user defined classes mutable

后端 未结 4 852
执笔经年
执笔经年 2020-12-16 11:03

Say I want to create a class for car, tractor and boat. All these classes have an instance of engine and I want to keep t

4条回答
  •  星月不相逢
    2020-12-16 11:24

    All objects (with the exception of a few in the standard library, some that implement special access mechanisms using things like descriptors and decorators, or some implemented in C) are mutable. This includes instances of user defined classes, classes themselves, and even the type objects that define the classes. You can even mutate a class object at runtime and have the modifications manifest in instances of the class created before the modification. By and large, things are only immutable by convention in Python if you dig deep enough.

提交回复
热议问题