12名無しさん
2019-07-19 23:25:21
ID:2od.PUZY

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 code, 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 += amount

a = Account()
print(a.bank.balance)

名前:

メール欄:

内容:


文字色

File: