Skip to content

Instantly share code, notes, and snippets.

@nattybear
Last active November 10, 2020 07:20
Show Gist options
  • Save nattybear/faa7e87e5e153658eaffb2628875d5d8 to your computer and use it in GitHub Desktop.
Save nattybear/faa7e87e5e153658eaffb2628875d5d8 to your computer and use it in GitHub Desktop.
암묵적 return None과 Zen of Python

암묵적 return None

파이썬 함수는 명시적으로 return을 적지 않으면 암묵적으로 None을 리턴한다.

아래 두 함수 explicitimplicit은 둘 다 None을 리턴한다.

def explicit():
  return None
  
def implicit():
  return

심지어 return 키워드를 생략해도 None을 리턴한다.

def f():
  print("This function returns None implicitly")
  
return_value = f()

print(return_value)  # None

Zen of Python

파이썬에는 Zen of Python이라고 하는 철학, 지침 같은 것이 있다.

여러가지 항목이 있는데 여기서 인용하고 싶은 것은 아래 두개이다.

  • Explicit is better than implicit.
  • Simple is better than complex.

명시적인 것이 좋은 사람은 return None을 적으면 된다.

반면에 간결함을 추구하는 사람이라면 굳이 적지 않아도 되겠다.

대문 링크

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment