← Quiz: Object Relationships: all 10 questions
Quiz: Object Relationships · Question 8 of 10
What does this print? (code)
What does this print?
class Player:
def __init__(self, name): self.name = name
class Team:
def __init__(self, players): self.players = players
p = Player("Mithali")
t1 = Team([p])
t2 = Team([p])
t1.players[0].name = "Mithali Raj"
print(t2.players[0].name)
- A.Mithali
- B.Mithali Raj
- C.AttributeError
- D.None
Answer & explanation
Correct answer: Mithali Raj
Both teams aggregate the same Player object, so a change through t1 is seen through t2.
Can you get the rest right without peeking?
Take the timed Quiz: Object Relationships quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →