Classes & Objects · Question 13 · Medium

fahrenheit is declared with @property and is accessed without brackets. What does this code print?

class Temp:
    def __init__(self, c):
        self.c = c
    @property
    def fahrenheit(self):
        return self.c * 9 / 5 + 32

t = Temp(100)
print(t.fahrenheit)
  1. 212.0
  2. 212
  3. TypeError
  4. AttributeError
Answer and explanation

Answer: A. 212.0

Explanation: @property lets a method be read like an attribute, so t.fahrenheit runs the method. 100 × 9 / 5 is 180.0 because / gives a float, and adding 32 gives 212.0.

Previous: A class method reads a counter that __init__ increases on the class. What is… · Next: What is the key difference between a method marked @classmethod and one marked…

Practise classes & objects

Try a fresh set of classes & objects questions with an explanation after every answer, free and without signing up: Classes & Objects practice. Or sit a full placement mock test.

More classes & objects questions

More python practice

Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge