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.
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
.
shapes
, not introcs from the video.)
shapes
, not introcs from the video.)
shapes
, not introcs from the video.)
Optional reading: 15.3 - 15.8 (html version)
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).
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.