引数のデフォルト値

投稿者: | 2月 23, 2021

“my_func(仮引数1, 仮引数2, 仮引数3=値)” のような関数の場合、仮引数を引数順に入れるだけでなく、引数名=値としても渡しても問題ない。

def location(city, state, country='Japan'):
    print('I live in ', country)
    print('My company is located in', city,',', state, '.')

location(state='Tokyo', city='chiyoda')

location('Manhattan', 'New York', 'United States')
I live in  Japan
My company is located in chiyoda , Tokyo .
I live in  United States
My company is located in Manhattan , New York .