## 1. CamelCasing for classes#class Account: def __init__(self): # 2. to refer to the inner class, you must use self.Bank # 3. no need to use an inner class here self.bank = self.Bank() class Bank: def __init__(self): self.balance = 100000 # 4. in your original pre, you had a method with the same name as # the attribute you set in the constructor. That meant that the # method was replaced with a value every time the constructor was # called. No need for a method to do a simple attribute lookup. This # is Python, not Java. def withdraw(self, amount): self.balance -= amount def deposit(self, amount): self.balance += amounta = Account()print(a.bank.balance)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)