LoginSignup
1
1

More than 5 years have passed since last update.

Pythonの固定引数は固定引数じゃないこともある

Posted at

Python1の関数定義は

def func(a, b):
    # aとbとが非対称になるように定義しておく
    return a + 2 * b

みたいにやる。この関数を呼び出すときは、

assert func(1, 2) == 5

という感じになる。これは

assert func(a=1, b=2) == 5

というようにも呼び出せる。このとき、

assert func(b=2, a=1) == 5

なんてこともできる2
固定とはなんだったのか...


  1. Python 3.5.0で動作確認 

  2. functools.partial みたいなのをやるときに便利 

1
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1