运行文档测试后,“什么都没有”是什么意思?

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

我正在制作一种方法来查找二叉树中的最大值,我认为我做对了,但是当我在其上运行我的文档测试时,它说的是预期值,但然后说“什么也没有”。我不确定这意味着什么或为什么会发生。

def best_apartment(self) -> None:
    """Return (one of) the apartment(s) with the best evaluation
    score in the BSTTree.
    >>> apartments = read_apartment_data("apartments.csv")[0:300]
    >>> bst = BSTTree()
    >>> bst.build_tree(apartments)
    >>> bst.best_apartment()
    PRIVATE: 80
    """

    if self.is_empty():
        return None

    current_node = self
    while current_node.right is not None:
        current_node = current_node.right

    return current_node.apartment

这是我的方法代码

python doctest
1个回答
0
投票

“Got Nothing”表示没有输出。

在这种情况下,这是因为在交互模式下,Python 不显示

None
值。例如:

>>> None  # No output
>>> 
>>> lst = []
>>> lst.append(1)  # This function returns None, so there's no output
>>> lst
[1]

您只需将文档测试中的代码复制到交互式会话中并运行它即可亲自确认这一点。

所以,问题是你的函数正在返回

None
。它在哪里做到这一点?
if self.is_empty():
。所以根本问题不在您此处显示的代码中。

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