LoginSignup
2
2

More than 3 years have passed since last update.

複数の戻り値の返し方についての備忘録

Last updated at Posted at 2019-05-14

カンマ区切りはpythonソース上でタプルと見なされます。
()をつけた方が親切なのでつけてもいいと思います。

def hoge():
    # ("id", "name")とみなされる
    return "id", "name"

# タプルをアンパック
id, name = hoge()

タプルはimmutableであり、hasableな値です。
listと違い、
後からの要素の変更や追加が不可であり、
タプルごと辞書のキーに使うことができます。

参考

Pythonの関数で複数の戻り値を返す方法

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