Class vocabulary

  • Attributes (fields) — data the class holds; methods — behaviors it exposes
  • Instance method → self/this; class method → cls; static method → no self
  • __str__ / toString() — human-readable string representation
  • Encapsulation — bundle data + behavior; hide internal state behind a public interface
  • Dependency injection — pass dependencies via constructor instead of creating them internally

Question 0 of 5

How would you describe this class in one sentence?

class BankAccount:
  def __init__(self, owner, balance=0):
    self.owner = owner
    self._balance = balance
  def deposit(self, amount): ...
  def withdraw(self, amount): ...
  def get_balance(self): ...