CSE 1010 Lecture Notes - Lecture 18: Instance Variable, Init
CSE 1010 verified notes
18/29View all
Document Summary
Cse 1010 - introduction to computing for engineers. Representing a checking account (continued from last class): Create a function to withdraw money from the account: def withdraw(acct, amount): bal = acct["bal"] newbal = bal - amount acct["bal"] = newbal. Or a shorter version of this function: def withdraw(acct, amount): acct["bal"] -= amount. Let"s fix the function to represent what would happen if there"s not enough funds in the account: def withdraw(acct, amount): if acct["bal"] >= amount: acct["bal"] -= amount else: print("insufficient funds") This is what it would look like if you test it out in idle: If you store an account in a variable and you know the name of the variable, then you have the account"s personal information: name and balance. That would be accessible by the public, too! Class: a template or blueprint that contains attributes that each instance of a class must have. Instance: an individual object that belongs to a class.