Overview
Model your program around objects that bundle state and behaviour into reusable, modular classes.
- class & __init__ constructor
- Instance methods & self
- Encapsulation
- Inheritance basics
Short Course
A class is a blueprint for objects. __init__ runs when you create an
instance; self refers to that instance.
class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed
def bark(self):
return f"{self.name} says Woof!"
dog = Dog("Rex", "Labrador")
print(dog.bark()) # -> Rex says Woof!
Task
Design a BankAccount class. deposit(amount) and withdraw(amount) should
update and return the new balance.
Test Suites
Pending
Stdout