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()Class with Method
Related Posts
More content you might like
Code
javascript
JavaScript Class with Constructor and Method
No preview available for this content.
Jan 26, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!