Classes Introduction

Classes allow us to define a new data type and allow us to organize our programs in a different way (Object Oriented Programming, a.k.a. OOP, a class is an object). An abstract data type has two parts: (1) attributes and (2) the operations that can be done on data of that type.

Readings from the book The Practice of Computing Using Python.

Chapter 11: Introduction to Classes

Section 9.6: Scope—The Full Story

Videos

  1. Objects and Object-Oriented Programming (OOP)
    1. Object-Oriented Programming (Video)
    2. Building our own class (object) (Video I, Video II)
    3. class MyClass (object):
          def __init__ (self, parameters):
              suite-of-statements # initialize attributes
          def some_method (self, parameters):
              suite-of-statements 
  2. Making a Clock class (Video)
  3. Unqualfied Names (LEGB)
  4. Unqualified names do not have a dot.
    Scope rules for unqualified names:

    • Local: inside the current function
    • Enclosing: in an outer function
    • Global: the module's global names
    • Built-in: Python's standard library

    1. LEGB (Video)
  5. Qualfied Names (LCB)
  6. Qualified names do not have a dot.
    Scope rules for qualified names:

    • Local: inside the current object
    • Class: inside the class definition
    • Base: inside the base class

    1. LCB (Video)

Assignments

  1. Chapter 11 Exercises on Codio
  2. Lab9 (do pre-lab first on D2L)
  3. Lab10 (do pre-lab first on D2L)
  4. Project 05(due in a week)
  5. Extra Credit 2(due 06/29, almost 2 weeks)