My QA Projects

QA Projects I was involded.

View on GitHub

Setters and getters

Getter (getter method, accessor method):

Setter (Setter method, also known as a mutator method):

class Person:
    def __init__(self, name):
        self._name = name  # Private attribute

    def get_name(self):
        return self._name

    def set_name(self, name):
        if isinstance(name, str):
            self._name = name
        else:
            raise ValueError("Name must be a string.")

# Usage
person = Person("Alice")
print(person.get_name())  # Output: Alice
person.set_name("Bob")
print(person.get_name())  # Output: Bob
person.set_name(123)  # Raises ValueError