Class
Object-Oriented Programming
In the object-oriented paradigm each object is an instance of a class.
Class
2.3.1 Example: CreditCard Class
The Self Identifier
class CreditCard:
def __init__(self, customer, bank, acnt, limit, apr):
self._customer = customer
self._bank = bank
self._account = acnt
self._limit = limit
self._balance = 0
def get_customer(self):
return self._customer
def get_bank(self):
return self._bank
def get_account(self):
return self._account
def get_limit(self):
return self._limit
def get_balance(self):
return self._balance
def charge(self,price):
if price + self._balance > self._limit:
return False
else:
self._balance += price
return True
def make_payment(self, amount):
self.baance -= amount
The Constructor
A user can create an instance of the CreditCard class using a syntax as:
cc = Credit('John Doe', '1st bank')
๋ณ์๋ช ์ _๋ถ์ด๋ ์ด์ : https://mingrammer.com/underscore-in-python/
Iterators
super() is calling the inherited constructors. This method calls the CreditCard superclass.
Last updated
Was this helpful?