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.

Lecture Prep

Read: 2 short sections from Ch 15 of textbook
  1. 15.1 Programmer-defined types
  2. 15.2 Attributes
Watch:
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: 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: use our module shapes, not introcs from the video.)
  3. Object Attributes (5 minutes) An attribute is a variable in an object. (Remember: use our module shapes, not introcs from the video.)

Optionally, Read: 15.3 - 15.8


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 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).

Questions and Answers: check the answers after you try them on your own!

Link to Lecture Recording