[Python] Python: how to sum/multiply an int with the value of a @property

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    The name property stands in the way here, so my searches has been unsuccessful. What I want to accomplice is multiply (sum , subtract, ...) an integer value to a value coming from a property (meaning @property):

    class A:
    __att = 3
    @property
    def att():
    return __att

    def test_method(self):
    return 3*A.att

    a = A()
    x = a.test_method()


    but I get TypeError: unsupported operand type(s) for *: 'int' and 'property'

    I understand the meaning of the message: it's sort of trying to multiply an int to a method name instead of its result, but for properties, shouldn't it be transparent? I do not understand what I'm missing here.

    Continue reading...

Compartilhe esta Página