Preferred way of defining properties in Python: property decorator or lambda?

Posted by parxier on Stack Overflow See other posts from Stack Overflow or by parxier
Published on 2010-03-09T04:00:43Z Indexed on 2010/03/09 4:06 UTC
Read the original article Hit count: 241

Filed under:
|
|
|

Which is the preferred way of defining class properties in Python and why? Is it Ok to use both in one class?

@property
def total(self):
    return self.field_1 + self.field_2

or

total = property(lambda self: self.field_1 + self.field_2)

© Stack Overflow or respective owner

Related posts about python

Related posts about property