i want to print the right boundary nodes of a tree except the leaf node

Solution for i want to print the right boundary nodes of a tree except the leaf node
is Given Below:

I want to print the right boundary nodes of a tree except the leaf node i saw the solution and this was the code

    # base case: root is empty, or root is a leaf node
    if root is None or not root.right and not root.left:
        return

    # recur for the right child of `root` if it exists;
    # otherwise, recur for the left child
    printRightBoundary(root.right if root.right else root.left)

    # To ensure bottom-up order, print the value of the nodes
    # after recursion unfolds
    print(root.data, end=' ')
    

enter image description here

my question is when the function is recursively called and finally the value of root 14 is passed in the function and then

if root is None or not root.right and not root.left:
        return

runs and after that

printRightBoundary(root.right if root.right else root.left)

and lastly

print(root.data, end=' ')

AND 14 is printed

my question is what happens after this…. how are 7 and 3 printed how does control go back to
printRightBoundary(root.right if root.right else root.left) for printing of 7 and 3 when the function is not called again