Lesson 25 of 55 · Python
OOP Basics – Classes
Duration: 20 minutes
Lesson 25 of 55 · Python
Duration: 20 minutes
python\nclass Person:\n def __init__(self, name, age):\n self.name = name\n self.age = age\n\n def greet(self):\n return f'Hi, I\'m {self.name} and I\'m {self.age} years old.'\n\nbob = Person('Bob', 28)\nprint(bob.greet())\n\n\nThe __init__ method is the constructor; it runs automatically when you create a new object.\n