I try to instanciate two objects of a house with a bedroom and a living room. If i change the pieces of furniture in one house the other one should not change.
class room:
def __init__(self,name,piecesoffurniture):
self.name=name
self.piecesoffurniture=piecesoffurniture
class house:
def __init__(self,rooms):
self.rooms=rooms
bedroom=room("bedroom",2)
livingroom=room("livingroom",3)
rooms=[]
rooms.append(bedroom)
rooms.append(livingroom)
myhouse=house(rooms)
yourhouse=house(rooms)
myhouse.rooms[0].piecesoffurniture=4
print(bedroom.piecesoffurniture)
print(yourhouse.rooms[0].piecesoffurniture)
output:
4
4
This is a sample code for my program where the constructor of room is very slow and the constructor of house is very fast.