Python 为什么博士考试不及格?

Python 为什么博士考试不及格?,python,class,doctest,Python,Class,Doctest,我用Python创建了一个类来执行一些基本操作 class perform(object): def add(self, first, second): """Adds two numbers >>>perform().add(1, 2) 3 Also adds string >>>perform().add('some', 'thing') 'somet

我用Python创建了一个类来执行一些基本操作

class perform(object):

    def add(self, first, second):
        """Adds two numbers
        >>>perform().add(1, 2)
        3
        Also adds string
        >>>perform().add('some', 'thing')
        'something'
        """
        return first+second

我不明白为什么添加函数的doctest失败。

您需要在docstring中添加一些空格和空行

class perform(object):
    def add(self, first, second):
        """Adds two numbers
        >>> perform().add(1, 2)
        3

        Also adds string
        >>> perform().add('some', 'thing')
        'something'
        """
        return first+second

doctest没有告诉您它失败的确切原因吗?请注意文档中包含的内容:@HimanshuMishra doctest将查找空行或以
>
开头的行,以确定预期输出何时结束