Concept
Classes vs Instances: Blueprint vs Concrete Object
A `class` is an architectural blueprint. An `instance` is an actual object stamped out in memory using that blueprint.
python
class Robot:
pass
r1 = Robot() # Instance 1
r2 = Robot() # Instance 2
print(r1 is r2) # False (two distinct objects)
# 116. Classes vs Instances: Blueprint vs Concrete Object A `class` is an architectural blueprint. An `instance` is an actual object stamped out in memory using that blueprint: ```python class Robot: pass r1 = Robot() # Instance 1 r2 = Robot() # Instance 2 print(r1 is r2) # False (two distinct objects) ``` Think of a class as an architectural blueprint for a house. An instance is the physical building created with concrete and wood at an actual street address in memory.
Checkpoint
In `bot = Robot()`, what is `Robot` and what is `bot`?
Practice
Define an empty class named `Player`. Instantiate two separate instances `p1` and `p2`. Print `isinstance(p1, Player)`.
01
Tap code blocks below to assemble
Available Blocks