Q: Confused on return statements in python So I am trying this leetcode problem and I believe I have the solution, however my return statement isn't returning anything.
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def searchBST(self, root, val):
        def search(node):
            print(node.val)
            if node.val == val:
                print('found', node.val)
                return node
            elif node.left != None:
                search(node.left)
            elif node.right != None:
                search(node.right)
        return search(root)

https://leetcode.com/problems/search-in-a-binary-search-tree/description/
That's the link to the problem, basically it inputs a BST tree and asks for a specific node, and i must return that node as the root along with it's children and grandchildren, etc.
My print statements that include the quotes 'found' prints the node in question, however my return statement is not returning anything to return to the compiler. If I put it outside entirely of the if and elif clause, it returns the found nodes parent...
I am sure this is an easy fix, but I am confused as to why it's not working and reviewing other issues posted here wasn't helping me so was wondering if anybody could explain why it doesn't work so that I may fix it? I believe I've used a return statement in a if/elif statement before and it returns the value if met, and ends the function...totally lost and probably just overlooking something simple. 
Thank you for reading!

A: You have few errors in your code:
1) You don't have return in all code cases in search function. This means that it will return None in all cases except case when root is node that you need.
2) Look at this fragment of code:
elif node.left != None:
    search(node.left)
elif node.right != None:
    search(node.right)

In BST left node value is always < than parent's node value and right node value is always > than parent's node value. This is how values are stored inside tree. You don't need to check call search for both child nodes:
def searchBST(self, root, val):
    def search(node):
        print(node.val)
        if node.val == val:
            print('found', node.val)
            return node
        elif node.val > val and node.left is not None:
            return search(node.left)
        elif node.val < val and node.right is not None:
            return search(node.right)
        else:
            return None  # value not found

    return search(root)

