Skip to content

Instantly share code, notes, and snippets.

@nattybear
Last active March 1, 2021 15:37
Show Gist options
  • Save nattybear/f0d857406ec601531390239a38196e4e to your computer and use it in GitHub Desktop.
Save nattybear/f0d857406ec601531390239a38196e4e to your computer and use it in GitHub Desktop.
파이썬 unpack

return 다음에 여러 값을 적으면 여러 개를 리턴하는 것 같지만 사실은 한 개의 튜플을 리턴합니다.

def f():
  return 1, 2  # return (1, 2)

result = f()

print(type(result))  # tuple

한편 한 개의 튜플 안에 있는 여러 값들을 어떤 함수의 인자로 각각 따로 넣고 싶을 때는 아래처럼 *을 이용하면 됩니다.

def add(x, y):
  return x + y
  
pair = (1, 2)

add(*pair)  # 3

따라서 질문하신 코드에 적용해보면 아래처럼 하면 되겠습니다.

minGrade(*main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment