LoginSignup
2
1

More than 5 years have passed since last update.

Python: 関数の引数について

Posted at

関数の引数

関数を定義

引数を受取り、出力する関数を定義する

def func(x, y, z):
    print(x, y, z)

続けて2つの引数をtupleとdictで定義する

# tuple型
tuple_arg = (1, 0, 1)

# dict型
dict_arg = {'x': 1, 'y': 0, 'z': 1}

tupleを関数funcの引数に渡してみると

func(*tuple_arg)
>>> 1, 0, 1

dictを関数funcの引数に渡してみると

func(**dict_arg)
>>> 1, 0, 1

どちらの場合も渡された型から、引数を認識してくれて値を展開してくれる。

2
1
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
2
1