CSE 1010 Lecture Notes - Lecture 18: Instance Variable, Init

38 views3 pages
Verified Note

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.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents