What two design decisions turn a real-world thing into a Python type — and why is a car's blueprint never the only right one?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Every object carries a type, and the type is what decides which operations the object will accept. Work out, in your head, the type of each of these six expressions:
7 / 27 // 2"7"[7, 7](7, 7){7: "seven"}Assign to value_types a list of those six types, in that order. Write the types themselves — int, not the string "int".
Objects, types, and the word instance
Record that every int, float, string, list and dictionary is an object whose type fixes the operations available on it, and name 1234 as an instance of int.
The two decisions behind a new object type
State the two design decisions: what data represents the object, and what behaviors form the interface other programmers and objects use, and write both down for one type of your choice.
The car blueprint as a design choice
Write the simple car as length, width, height and color, add a richer alternative such as horsepower, doors and capacity, and list interface behaviors like honking, changing color and driving.