title: Returning value of None object
body: <p>I have got adding method in my AVL tree implementation.</p>
  
  <pre><code>class Node:    
      def __init__(self, data, left = None, right = None, height = -1):
          self.data = data
          self.left = left
          self.right = right
          self.height = height
      def addNode(self, data):
          if self.data &gt; data:
              '''Adding to left subtree'''
              if self.left is None:
                  self.left = Node(data)
              else:
                  self.left.addNode(data)
                  if ( abs(self.right.height - self.left.height) == 2):
                      ''' Then we need to balance a subtree''' 
                      print("Rebalancing after inserting", data)
                      if (data &lt; self.left.data):
                          self.rotateLeft()
                      else:
                          self.doubleRotateLeft()
  
          elif self.data &lt; data:
              '''Adding to right subtree'''
              if self.right is None:
                  self.right = Node(data)
              else:
                  self.right.addNode(data)
                  if ( abs(self.right.height - self.left.height) == 2):
                      ''' Then we need to balance a subtree'''
                      print("Rebalancing after inserting", data)
                      if (data &lt; self.right.data):
                          self.rotateRight()
                      else:
                          self.doubleRotateRight()
  </code></pre>
  
  <p>But when I try to do</p>
  
  <pre><code>self.right.height
  </code></pre>
  
  <p>and self hasn't got right object then it will not return height, even default value is -1. How can I fix it? I am trying to make as less duplicated code in this method as possible</p>