LoginSignup
0
2

Pythonで「関数を呼び出すときに引数を使って値を渡す」の動作を確認してみた

Posted at

概要

Pythonで「関数を呼び出すときに引数を使って値を渡す」の動作を確認してみました。
以下のページを参考にしました。

実装

以下のファイルを作成しました。

sample.py
def myfunc(str1, num1):
    print("Name: " + str1 + ", Old: " + str(num1))

myfunc("Yamada", 28)
myfunc("Suzuki", 32)

def myfunc(mylist):
    print("Name: " + mylist[0] + ", Old: " + str(mylist[1]))

myfunc(["Yamada", 28])
myfunc(["Suzuki", 34])

def myfunc(num1, num2):
    return num1 + num2

myfunc(10, 20)

以下のコマンドを実行しました。

$ python3 sample.py 
Name: Yamada, Old: 28
Name: Suzuki, Old: 32
Name: Yamada, Old: 28
Name: Suzuki, Old: 34

まとめ

何かの役に立てばと。

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