Skip to content

Sep 17: Prac2, 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

  • Due today: HW4 Reflection
  • Read Week 5 – ideally:
    • 1st half before Friday
    • 2nd half before Monday
  • Submit HW 5 – ideally:
    • 1 and 2 before Friday
    • 3 and 4 before Monday
  • Upcoming events
    • Wed 9/17 at 6:30 in King 243: First-Year Kickoff (make-up)
    • Fri 9/19 at 11:30 in King 259: What is Research?

HW4 Debrief

[10 min]

Some highlights:

  • Docstrings are painful to write but really help
  • The __main__ block can be used for testing
  • Division/modulo can be used to extract digits

Practice Quiz 2

[25 min]

  • Don't need to log in as student for practice quizzes
    • But don't use any existing files during the quiz
    • Also don't open any other windows or tabs
  • Practice not using Thonny for the first 10 minutes
  • Feel free to ask questions during the practice quiz

Wk05 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 object id's
  • A container is an object that contains (references) other objects
    • list: [1, 2, 3] in brackets
    • tuple: (1, 2, 3) in parentheses
    • set: {1, 2, 3} in braces
    • dict: {"one": 1, "two": 2, "three": 3} braces + colons
  • Every variable references exactly one object