Skip to content

Sep 20: Quiz 2a, Objects and Types

Learning Objectives

After today's class, you should be able to:

  • Explain the difference between a variable and an object.
  • Name and describe three examples of a container type.

Reminders

  • Read Ch 5 – ideally:
    • 1st half before Friday
    • 2nd half before Monday
  • Submit HW 5 – ideally:
    • 1 and 2 before Friday
    • 3 and 4 before Monday

HW4 Debrief

[10 min]

Some highlights:

  • Functions can eliminate any duplicate code
  • Docstrings are painful to write but really help
  • The __main__ block can be used for testing
  • Complex math can be broken down into steps
  • Division/modulo can be used to extract digits

Quiz 2a

[25 min]

Instructions:

  • Log in as student
  • Only two windows:
    1. Thonny
    2. Web browser
  • Web traffic monitored
  • Log out when finished

Ch05 Preview

[15 min]

  • Variables and objects are two different concepts
Example Variable (Name) Object (Value)
x = 5 x the integer 5
y = 1.2 y the float 1.2
z = 'A' z the string 'A'
p = True p the boolean True
q = None q the None object
import math math the math module
def hi() hi the hi function
  • Every object has a value, a type, and an identity
    • type() and id() functions
    • is keyword compares id's
  • A container is an object that "contains" (references) other objects
    • list: [1, 2, 3] brackets
    • tuple: (1, 2, 3) parentheses
    • set: {1, 2, 3} braces
    • dict: {"one": 1, "two": 2, "three": 3} braces + colons
  • Every variable references exactly one object