slash asterisk parameters functions
Source
- the slash (
/) separates positional-only arguments from positional or keyword arguments - the asterisk (
*) separates positional or keyword arguments from keyword-only arguments - if both occur in a parameter list, the slash (
/) must come before the asterisk (*)
def slash_usage(positional_only, /, either):
print(positional_only, either)
def asterisk_usage(either, *, keyword_only):
print(either, keyword_only)
def both_usage(positional_only, /, either, *, keyword_only):
print(positional_only, either, keyword_only)- using slash (
/) and asterisk (*) directly after each other, forces everything left of the slash to be passed by position-only and everything to the right to be passed by keyword-only
def both_usage(positional_only, /, *, keyword_only):
print(positional_only, keyword_only)