Question 19: Using Property Decorators in Python

This question challenges you to consider how Python handles decorators.

A decorator feature in Python wraps in a function, appends several functionalities to existing code, and then returns it. 

@property decorator is a built-in decorator in Python that helps define the properties effortlessly without manually calling the inbuilt function property().

Question: Property Decorators

Given the following Python code, what will be the output and why?

class Website:
    def __init__(self):
        self._domain = None
    
    @property
    def domain(self):
        return self._domain
    
    @domain.setter
    def domain(self, value):
        self._domain = value

# Example usage
obj = Website()
obj.domain = "example.com"
print(obj.domain)















Answer: A

The code correctly sets and gets the value of the variable.

Leave a Reply