title: How to build a binary tree in Python
body: <p>I am trying to build a binary tree, but stuck at adding two nodes to root.</p>
  
  <p>What function should I write to enable adding node to these two nodes?</p>
  
  <p>I have the following code:</p>
  
  <pre><code>class Btree:
          def __init__(self, root):
                  self.key = root
                  self.lc = None
                  self.rc = None
  
          def insert_lc(self, newNode):
                  if self.lc == None:
                          self.lc = Btree(newNode)
                  else:
                          t = Btree(newNode)
                          t.lc = self.lc
                          self.lc = t
          def insert_rc(self, newNode):
                  if self.rc == None:
                          self.rc = Btree(newNode)
                  else:
                          t = Btree(newNode)
                          t.rc = self.rc
                          self.rc = t
  
          def get_rc(self):
                  return self.rc
          def get_lc(self):
                  return self.lc
  
          def set_Root(self, val):
                  self.key = val
          def get_Root(self):
                  return self.key
  
  r = Btree(1)
  r.insert_lc(2)
  r.insert_rc(4)
  </code></pre>
  
  <p>I think I need a function so I can add left child and right child to nodes which have value 2 and 4 </p>