MIT Week6 homework -- Classes Question: Why does the code below output 10:30? Also, the homework asks us if paris_clock and boston_clock are different objects. I did an "is" test which returns True. But what am I supposed to learn from this? class Clock: def __init__(self, time): self.time = time def print_time(self): print self.time boston_clock = Clock('5:30') paris_clock = boston_clock paris_clock.time = '10:30' boston_clock.print_time() #ends up printing 10:30
Can anyone tell me if I can edit a question after I post it?
i guess the point was to show that boston and paris are indeed the same object - when you set paris to 10:30, you have also set boston, the same object, to 10:30. paris would be an independant object had you used paris = Clock('5:30'), which would not have had any effect on boston.
Paris and Boston clock are different object,the issue is assignment ,where Boston_clock is been assigned to Paris_clock, good lock
Join our real-time social learning platform and learn together with your friends!