Saltar para o conteúdo principal
🔒 Modo de pré-visualização. As primeiras quinze aulas de Foundations são grátis; esta é Pro. Inicie um trial de 7 dias para desbloquear o editor, as dicas AI e o resto do programa. Cartão necessário, cancele a qualquer momento no Dashboard.Iniciar trial de 7 dias →
← CursosSenior Deep-DivesMódulo 1 · Simultaneidade e aspectos internos assíncronosDescritorespredict6 / 161
+100 XP
Tarefa🌐 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.
Prevê a saída

Lê o código com atenção

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)

O que o programa vai imprimir? Escreve aqui: