09-28

Reading: classes in Python. An introduction to object-oriented programming in Python.

Section 9.2 is esoteric, you should skip it on the first reading.

Section 9.3 is important.

  • Translate into Python: Candy class
  • Translate into Python: Animals: Borzoi etc. Feel free to take some liberties with the specification.
  • USACO Bronze: bucket brigade

Concepts

  • The constructor: __init__
  • Explictly using functions from a superclass: super()
  • Control how a class prints out like Java’s toString() method: __str__

Additional Advanced Reading

This is purely for your own elightenment. These readings will never be used in class. Python is not like Java. In Python, a class is allowed to inherit from more than one superclass.