0% found this document useful (0 votes)
3 views2 pages

Class

The document defines a Person class with attributes for name, age, and gender. It includes methods for greeting and checking if the person is an adult based on their age. The class is initialized with the specified attributes and provides functionality to interact with the person's data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Class

The document defines a Person class with attributes for name, age, and gender. It includes methods for greeting and checking if the person is an adult based on their age. The class is initialized with the specified attributes and provides functionality to interact with the person's data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

class Person:

"""
A class to represent a person.

Attributes:
name (str): The name of the person.
age (int): The age of the person.
gender (str): The gender of the person.

Methods:
greet(): Prints a greeting message with the person's name.
is_adult(): Returns whether the person is an adult (age >= 18).
"""

def __init__(self, name, age, gender):


"""
Initializes the Person class with name, age, and gender.

Parameters:
name (str): The name of the person.
age (int): The age of the person.
gender (str): The gender of the person.
"""
self.name = name
self.age = age
self.gender = gender
def greet(self):
"""Prints a greeting message with the person's name."""
print(f"Hello, my name is {self.name}.")

def is_adult(self):
"""
Checks if the person is an adult.

Returns:
bool: True if the person's age is 18 or older, False otherwise.
"""
return self.age >= 18

You might also like