Python Classes and Objects

# Define a class named Person
class Person:
    # Constructor method to initialize the object
    def __init__(self, name, age):
        self.name = name    # Attribute: name
        self.age = age      # Attribute: age
    
    # Method to greet the person
    def greet(self):
        print(f"Hello, my name is {self.name} and I am {self.age} years old.")

# Create an object (instance) of the Person class
person1 = Person("Alice", 30)

# Access attributes and call methods of the object
print(person1.name)   # Output: Alice
print(person1.age)    # Output: 30
person1.greet()       # Output: Hello, my name is Alice and I am 30 years old.