[Python] What is the difference between default and required parameters?

Discussão em 'Python' iniciado por Stack, Junho 1, 2025.

  1. Stack

    Stack Membro Participativo

    Create a new function named defaults with two parameters:

    1. my_optional which has a default value of True
    2. my_required which is a required param and has no default value

    Return the following logical comparison: my_optional is my_required

    Expected output:

    >>> defaults(True)
    True

    >>> defaults(True, False)
    False

    >>> defaults(False, False)
    True


    This is my attempt:

    def defaults(my_optional, my_required)
    my_optional = True
    return my_optional is my_required


    I received the error: "defaults is missing positional argument: my_required"

    Continue reading...

Compartilhe esta Página