Python Programming - Encapsulation - Discussion

Discussion Forum : Encapsulation - General Questions (Q.No. 64)
64.
What is the purpose of the following Python code?
class TemperatureConverter:
    def __init__(self, celsius):
        self._celsius = celsius

    @property
    def fahrenheit(self):
        return self._celsius * 9/5 + 32
To create a new instance of the class
To provide a setter method for the celsius variable
To calculate and provide read-only access to the temperature in Fahrenheit
To expose all internal details of the class
Answer: Option
Explanation:
The @property decorator is used to create a read-only property 'fahrenheit' that calculates the temperature in Fahrenheit based on the stored Celsius value.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.