title: How do you change the value of one attribute by changing the value of another? (dependent attributes)
body: <p>When assigning attributes to objects, I often find that I have to change attributes that are dependent upon others, say, light and darkness. Here's an example:</p>
  <pre><code>class shade:
      def __init__(self, light):
          self.light=light
          self.darkness=100-light
  
      def __str__(self):
          return (str(self.light) +  ',' + str(self.darkness))
  
  
  
  &gt;&gt;&gt; shade1=shade(30,70)
  &gt;&gt;&gt; shade1.light
  30
  &gt;&gt;&gt; shade1.darkness
  70
  </code></pre>
  <p>Now, while that is cool and all, what I would like is the same process to occur, but within the same object if a change in one attribute occurs. If I reset the property of light, I want darkness to incr/decr accordingly. I can do this with a function if it works to change the property of light, returning the new value of light/darkness, but I'd like a way to do this if I change the property of light simply by re-assigning its value, without the use of functions. Like this:</p>
  <pre><code>&gt;&gt;&gt; shade1.light=50
  &gt;&gt;&gt; shade1.light
  50
  &gt;&gt;&gt; shade1.darkness
  50
  </code></pre>