Lesson: User Defined Types

Learning Objectives

Students will be able to...

  • Define and identify: class, instance, object, attributes
  • Create a class and instantiate
  • Add attributes to an instance
  • Use attributes and class

Materials/Preparation

  • Do Now
  • Example
  • Lab
  • Associated Reading - section 6.1 of Book
  • Read through the handout, lesson, and lab so that you are familiar with the requirements and can assist students

Pacing Guide

Duration Description
5 Minutes Do Now
10 Minutes Lesson
30 Minutes Lab
10 Minutes Discussion

Instructor's Note

  1. Do Now
    • Display the Do Now on the board.
  2. Lesson
    • Discuss Do Now
      • Ask the students what data type they thought would be helpful? Ask how they would print the full names.
      • Need something that says "I am type Pet"
    • class: a user defined type.
      • On board write syntax for creating a class: class Pet(object):
      • object : basis of object oriented programming. objects correspond to a real world object
      • instantiated: can create instances of a class by using Pet(). If you check the type of an instance it will be Pet
      • instances are mutable, they can be changed or updated
    • show Example on board.
      • Ask students what the difference is between this and the do now
      • Ask the students where the class is created.
      • Ask the students where the class is instantiated
        • Ask students what they think pet.full_name will do
          • explain concept of attribute
          • attribute: values assigned to an instance
    • can also create functions that take in classes and use their attributes
  3. Lab
    • Students will create RGB colors using class.
    • Create a function to merge two colors.
    • Check up their colors on a rgb website
  4. Debrief
    • Talk about any of the phrases or issues the students had. Did they find it easy to understand the code when they read it.