Python Properties और Class Methods क्विज़

यह Python quiz @property, setters, @classmethod और @staticmethod को cover करता है. आप computed attributes, read-only properties, alternative constructors और वे बारीक bugs trace करेंगे, जैसे setter में infinite recursion, जो code reviews और interviews में आते हैं.

कठिन 10 सवाल ~8 मिनट पास होने के लिए 80% Python 3.12

मोड चुनें

आप गेस्ट के तौर पर खेल रहे हैं: XP और streak सेव रखने के लिए साइन इन करें।

सैंपल सवाल

सवाल 1 / 10

यह code क्या print करता है?

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

t = Temp(100)
t.c = 0
print(t.f)
जवाब दिखाएं

B. 32.0 Property हर बार पढ़ने पर compute होती है, इसलिए वह current c use करती है, जो 0 है. / operator हमेशा float देता है, इसलिए result 32.0 है.

इस क्विज़ में क्या है

  • @property से computed attributes
  • Setters, validation और read-only properties
  • @classmethod और subclasses में cls
  • @staticmethod और उसे कब use करें
  • Properties से जुड़े common bugs

अक्सर पूछे जाने वाले सवाल

क्या अकाउंट ज़रूरी है?

नहीं। कोई भी खेल सकता है। XP, streak, badge और हिस्ट्री सेव रखने के लिए साइन इन करें।

कौन-सा Python वर्ज़न?

Python 3.12। आउटपुट वाले हर सवाल को कोड रन करके जांचा गया है।

क्या मैं इसे दोबारा दे सकता हूं?

हां। आपका बेस्ट स्कोर सेव रहता है, और हर बार सवाल और जवाब शफ़ल होते हैं।