title: Why do we need property in Python?
body: <p>I understand one of the main purpose to use property is for validation and formatting. For example, I have a User class shown below. And I want the firstname and lastname are capitalized when they are being set. Why do I need property if I can write the following code to achieve the same formatting result?</p>
  
  <pre><code>class User:
      def __init__(self, firstname, lastname):
          self.firstname = firstname
          self.lastname = lastname
  
      def __setattr__(self, attr, value):
          if attr == 'firstname':
              self.__dict__[attr] = value.capitalize()
          elif attr == 'lastname':
              self.__dict__[attr] = value.capitalize()
  </code></pre>