Published on January 26, 2024By DeveloperBreeze

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

    def greet(self):
        return f'Hello, my name is {self.name} and I am {self.age} years old.'

# Create an instance of Person
person = Person('Alice', 25)

# Call the greet method and store the result in 'greeting'
greeting = person.greet()

Comments

Please log in to leave a comment.

Continue Reading:

JavaScript Class with Constructor and Method

Published on January 26, 2024

javascript

PHP Class and Object Example

Published on January 26, 2024

php