title: Why my python code for Binary Search Tree is showing this weird error?
body: <p>Here is my code. I can't understand what I'm missing.</p>
  
  <pre><code>class Node:
      def __init__(self, data,left = None,right = None):
          self.data = data
          self.left = left
          self.right = right
  
  class BST:
      def __init__(self,root=None):
          self.root = root
      def insert(self,val):
          new_node = Node(val)
  
          if self.root == None:
              self.root = new_node
  
          else:           
              cur = self.root
              leaf = None
              while cur!=None:
                  leaf = cur
                  if val &gt;= cur.data:
                      cur = cur.right
                  else:
                      cur = cur.left
              if val &gt;= leaf.data:
                  leaf.right = new_node
              else:
                  leaf.left = new_node
  
      def preOrder(self,root):
  
          if root:
              print(root.data,end=' ')
  
              preOrder(root.left)
              preOrder(root.right)
  
  
  b = BST()
  b.insert(1)
  b.insert(2)
  b.insert(5)
  b.insert(3)
  b.insert(6)
  b.insert(4)
  b.preOrder(b.root)
  </code></pre>
  
  <p>This code is showing this error: <strong>NameError: name 'preOrder' is not defined</strong> How does it possible? I've defined the preOrder() in class BST. How can I solve this problem? And please explain the error so that I can understand my misunderstanding.</p>