are user defined classes mutable

后端 未结 4 853
执笔经年
执笔经年 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:29

    EDIT: This is conceptually wrong, The immutable object in python can shed some light as to why.

    class Engine():
        def __init__(self, sn):
            self.sn = sn
    
    a = Engine(42)
    b = a
    print (a is b)
    

    prints True.

提交回复
热议问题