Přejít k hlavnímu obsahu
🔒 Režim náhledu. Prvních patnáct lekcí Foundations je zdarma; tato je Pro. Spusťte 7denní trial pro odemčení editoru, AI nápověd a zbytku kurzu. Karta vyžadována, zrušte kdykoli v Dashboard.Spustit 7denní trial →
← KurzySenior Deep-DivesModul 1 · Concurrency & Async InternalsDeskriptorypredict6 / 161
+100 XP
Úkol🌐 shown in EN
📝 **Task:** Predict the exact output. The \`Tracker\` descriptor prints on bind / get / set. Three things to think about: (1) When does \`__set_name__\` run? (2) Does \`b.x = 10\` go through \`__set__\`? (3) When \`total = b.x + b.y\` runs, which calls fire and in what order? 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Předpověz výstup

Přečti kód pozorně

class Tracker:
    def __set_name__(self, owner, name):
        self.name = name
        print(f"bind:{name}")
    def __get__(self, instance, owner):
        if instance is None:
            return self
        print(f"get:{self.name}")
        return instance.__dict__.get(self.name, 0)
    def __set__(self, instance, value):
        print(f"set:{self.name}={value}")
        instance.__dict__[self.name] = value


class Box:
    x = Tracker()
    y = Tracker()


b = Box()
b.x = 10
b.y = 5
total = b.x + b.y
print(total)

Co program vypíše? Napiš sem: