为什么我在递归 DFS 之后打印了一个特殊字符?

Why I am getting a special character printed after the recursive DFS?

我有一个简单的深度优先搜索玩具代码,但为什么我在打印后得到 %?

# Definition for a  binary tree node
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None
    def dfs(t):
    if t==None:    
        print("",end="")    
    else:    
        print(t.val,end="")        
        dfs(t.left)        
        dfs(t.right)

t=TreeNode(1)
t.left=TreeNode(2)
t.right=TreeNode(3)
t.left.left=TreeNode(4)
t.left.right=TreeNode(5)
t.right.left=TreeNode(6)
t.right.right=TreeNode(7)
dfs(t)

输出:1245367%

这是您的 shell 提示。您的输出不以行终止符结尾,因此您的 shell 将其 "next command, please" 提示打印在与程序输出相同的行上。