Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

JohnM

  • 3 years ago

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

  • This Question is Closed
  1. JohnM
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Can anyone tell me if I can edit a question after I post it?

  2. snark
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  3. olasunmibo
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    Paris and Boston clock are different object,the issue is assignment ,where Boston_clock is been assigned to Paris_clock, good lock

  4. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy