I am just learning how to make classes and I was trying to complete one of my assignments but I was having difficulty making one the variables private. I am making an Account class that stores the ID, balance, and annual interest rate. All of these have default values or can be set. My code looks like this
class Account:
def __init__(self, ID=0, balance=100, annualInterestRate=0.0):
self.ID = int(ID)
self.balance = float(balance)
self.annualInterestRate = float(annualInterestRate)
account = Account()
print(account.ID)
print(account.balance)
print(account.annualInterestRate)
Everything works fine, but if I try making the the variables private(by adding "__" before the variable), and then try accessing the values, I get an AttributeError. Anyone know what I am doing wrong?
...
self.__ID = int(ID)
self.__balance = float(balance)
self.__annualInterestRate = float(annualInterestRate)
account = Account()
print(account.ID)
print(account.balance)
print(account.annualInterestRate)