Positional arguments, keyword arguments, default arguments

argument.py


#The default argument for desert is orange
def menu(drink, food, desert = 'orange'):
    print('drink:', drink)
    print('food:',food)
    print('desert:', desert)

#Function call by keyword argument (default argument is passed because desert does not specify anything)
menu(food ='egg', drink = 'beer')

Output result:

drink: beer
food: egg
desert: orange

Recommended Posts

Positional arguments, keyword arguments, default arguments
[Introduction to Udemy Python3 + Application] 50. Positional arguments, keyword arguments, and default arguments
Dictionary of keyword arguments
Python> positional arguments / keyword arguments> mixable> print (2, 3, 5, 7, 11, sep ='\ t', end ='')
Keyword arguments for Python functions
Mixed positional arguments, tuples and dictionaries
python> keyword arguments> hoge (** {'a': 1,'b': 2,'c': 3})
EP19 Provide Optional Behavior with Keyword Arguments