LinkedIn Python Skill Assessment Quiz Answers

Correct representation of doctest for function in Python

Latest Update on 25th January, 2022 by Certification Course Answers

Correct representation of doctest for function in Python

def sum(a, b):
    # a = 1
    # b = 2
    # sum(a, b) = 3

    return a + b
def sum(a, b):
    """
    a = 1
    b = 2
    sum(a, b) = 3
    """

    return a + b
def sum(a, b):
    """
    >>> a = 1
    >>> b = 2
    >>> sum(a, b)
    3
    """

    return a + b
def sum(a, b):
    '''
    a = 1
    b = 2
    sum(a, b) = 3
    '''
    return a + b

Correct Answer:

def sum(a, b):
    """
    >>> a = 1
    >>> b = 2
    >>> sum(a, b)
    3
    """

    return a + b

Explanation: Use """ to start and end the docstring and use >>> to represent the output. If you write this correctly you can also run the doctest using build-in doctest module

Latest Updates

No posts found in this category.