python optional positional argument code example

Example 1: optional argument python

def myfunc(a,b, *args, **kwargs):
      c = kwargs.get('c', None)
      d = kwargs.get('d', None)
      #etc
myfunc(a,b, c='nick', d='dog', ...)

Example 2: python positional argument

A function definition may look like:

def f(pos1, pos2, /, pos_or_kwd, *, kwd1, kwd2):
      -----------    ----------     ----------
        |             |                  |
        |        Positional or keyword   |
        |                                - Keyword only
         -- Positional only

where / and * are optional.
If used, these symbols indicate the kind of parameter by how
the arguments may be passed to the function:
      positional-only, positional-or-keyword, and keyword-only.
Keyword parameters are also referred to as named parameters.