Question 12
Back to Exercise
What is the output of the following Python program?
class Account:
kind = "Account"
def __init__(self, balance):
self.balance = balance
def __str__(self):
return f"{self.kind}: {self.balance}"
class Savings(Account):
kind = "Savings"
print(Account(100), Savings(500))
- A Account: 100 Account: 500
- B Savings: 100 Savings: 500
- C Account: 100 Savings: 500 Correct
- D TypeError
Correct Answer: Option C
Savings inherits __str__, but self.kind finds Savings' own class attribute.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!