An object is the value of, i.e., an instance of, a custom type. Yes, we get to create our own types beyond what is built-in in Python! Before you learn to create a custom type however, first you need to understand objects. We will look at how to create an object, how to access its attributes, and how to visualize it.

Activities before lecture

First read 2 short sections from Ch 15 of textbook

  1. 15.1 Programmer-defined types
  2. 15.2 Attributes

Next watch lesson videos

Note that we do not use the module introcs referenced in the lessons. Instead, we will use the module shapes created specifically for this lecture. Download this file shapes.py. Whenever the video mentions introcs, as you follow along you should use shapes instead. For example, instead of typing import introcs, you should type import shapes.
  1. Object Instantiation (4 minutes) The action of creating an object is called instantiation. (Remember to use our module shapes, not introcs from the video.)
  2. Object Visualization (6 minutes) Previously we drew diagrams to represent first variables and then function calls, now we discuss how to diagram an object. (Remember to use our module shapes, not introcs from the video.)
  3. Object Attributes (5 minutes) An attribute is a variable in an object. (Remember to use our module shapes, not introcs from the video.)

Optional reading: 15.3 - 15.8 (html version)


Lecture materials

Slides: individual slides for viewing, 6-up layout for printing

Examples: shapes.py (same file as above posted with the lesson videos), demoPoint3.py
To download the above .py files, right-click (Windows) or command-click (Macs) on the filename and then select "Save link as".
This way you choose where the files will be saved, instead of having your computer save to the default folder (from which you will later have to move your files for organization).

Lecture Recording

Answers to the 4 in-lecture questions (slides 20, 25, 27, 29) and one post-lecture question (slide 32): See the lecture slides file above for the questions. After solving the problems yourself, you can check your answers here. You can also use Python Tutor to help you visualize.