🧭Class
Also known as Class (Programming), Class Definition
A plan for making objects. It lists their data and their actions.
Think of it like
Think of it like a cookie cutter. You make one cutter, then press out lots of cookies.
Example
Emma writes a Dog class with a name and a speak method. She makes a dog called Rex from it, and Rex says woof.
Why it matters
Classes let you write the shape of a thing once and reuse it everywhere.
Definition
Example code
python
class Dog:
def __init__(self, name):
self.name = name
def speak(self):
return self.name + " says woof"
rex = Dog("Rex")
print(rex.speak()) # Rex says woofCommon mistake
Key takeaways
- 1A plan. Not a real thing yet.
- 2Data and actions. What each object holds and does.
- 3Many from one. Make as many as you need.