Skip to main content
3 of 3
deleted 2 characters in body
timgeb
  • 79.2k
  • 20
  • 129
  • 150

Should I use property or private attribute?

Suppose I create a class:

class SomeClass: def __init__(self, some_attribute): self._attribute = some_attribute @property def attribute(self): return self._attribute 

Then, I add a method new_method to my object that will use the "attribute". Therefore, should I use self._attribute or self.attribute?:

def new_method(self): DoSomething(self.attribute) # or DoSomething(self._attribute) 

Does it make any impact or difference?

Steven
  • 15.4k
  • 7
  • 49
  • 80