Code Examples
class Student:
"""Represents a student with name, age, and grades."""
# Class attribute — shared by ALL instances
school = "BitWithBite Academy"
def __init__(self, name, age, gpa=0.0):
# Instance attributes — unique per object
...
class ShoppingCart:
def __init__(self, owner):
self.owner = owner
self.items = []
def add(self, item, price):
self.items.append((item, price))
def total(self):
return sum(p for _, p in self.items)
# __str__...
class BankAccount:
_total_accounts = 0 # class attribute — tracked globally
INTEREST_RATE = 0.05 # constant — class attribute
def __init__(self, owner, balance=0):
self.owner = owner
self.balance = balance
BankAcc...