Picture of the authorDevGrads

Classes

Blueprints for creating objects that encapsulate data (attributes) and behavior (methods).

Example

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def introduce(self):
        print(f"Hi, I'm {self.name} and I'm {self.age} years old.")

person1 = Person("Charlie", 35)
person1.introduce()  # Prints "Hi, I'm Charlie and I'm 35 years old."