💡 What You'll Learn
Classes are blueprints for creating objects. They define what data (attributes) and actions (methods) objects will have. __init__ is called when creating a new object.
class_demo.py
1class Dog:
2 def __init__(self, name):
3 self.name = name
4 def bark(self):
5 print(f"{self.name} says woof!")
📺 Create a Dog object!
Click to create a dog!
🎯 Your Challenges
1Add Age
Add an age attribute to the Dog class
2Human Years
Add a method to calculate dog's age in human years
3Cat Class
Create a Cat class with a meow method
📚 What You Learned
class ClassName:defines a class__init__initializes new objectsselfrefers to the current object- Methods are functions inside a class