What it has vs what it does
Attributes vs Methods
The analogy
A house HAS things: a colour, four windows, an address. A house DOES things: the door opens, the lights switch on. Attributes are the nouns you can point at; methods are the verbs the house can perform.
Visualizer
What it has vs what it does
step 1 / 7HAS — attributes (nouns)
colour = "white"
windows = 4
lightsOn = false
DOES — methods (verbs)
openDoor()
switchLights()
repaint(colour)
Two columns. Things the house HAS, and things the house DOES.
class House:
def __init__(self):
self.colour = "white" # HAS
self.lights_on = False # HAS
def switch_lights(self): # DOES
self.lights_on = not self.lights_on
def repaint(self, colour): # DOES
self.colour = colourCheck yourself
openDoor() is a…