下图中有一段代码,在第11行显示p=self.parent,但这里self是root,而root没有parent,请解释一下

问题描述 投票:0回答:1

In the below photo there is a code in which at line 11 it showing the p=self.parent but here self is root,and root doesn't have parent,still the code works please explain

代码绝对有效,但我不明白 p=self.parent 是如何工作的,我认为这不是,请澄清 self.parent 指的是什么以及该过程如何继续查找通用树的级别

python tree
1个回答
0
投票

如果

root
没有父级,那么
p
将是
None
,不会进入循环并且
level
将(仍然)为 0。

© www.soinside.com 2019 - 2024. All rights reserved.