title: Class, and Recursion in Binary Tree Traversing
body: <p>I was trying to solve the Pre-order binary tree traversal in LeetCode where I wrote the following code:</p>
  <pre><code>  # Definition for a binary tree node.
     # class TreeNode:
     #     def __init__(self, val=0, 
      left=None, right=None):
     #         self.val = val
     #         self.left = left
     #         self.right = right
  class Solution:
    def preorderTraversal(self, root):
      if root is None:
       return []
      else:
       return [root.val] + 
  self.preorderTraversal(root.left) + 
  self.preorderTraversal(root.right)
  </code></pre>
  <p>Though the code worked, I was not able to understand two things:</p>
  <p>1)How does the system recognise root as TreeNode class when the definition of TreeNode is only a comment (using #)?</p>
  <p>2)I was getting the error preorderTraversal as not defined while trying to use it recursively, even when I had defined it earlier. Only by using the .self was I able to solve it. Is using .self always necessary for recursion?</p>
  <p>I am reall new to Python. Please help me clarify these questions.</p>