0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Python】可変長位置引数、可変長キーワード引数、アンパック

0
Posted at

【def func(*args, **kwargs)】
仮引数にアスタリスクを1つ付けて「*args」とすると、可変長の位置引数として実引数を受け取ります。
また、仮引数にアスタリスクを2つ付けて「**kwargs」とすると、可変長のキーワード引数として実引数を受け取ります。

【func(*num, **dic)】
実引数にアスタリスクを1つ付けて「*num」とすると、リストやタプルの要素をアンパックして渡します。
また、実引数にアスタリスクを2つ付けて「**dic」とすると、辞書の各キーと値を複数のキーワード引数として渡します。

なお、「args」と「kwargs」は慣例で使われている仮引数の名称のため、他の名称でも問題ありません。重要なのはアスタリスクの数です。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?