Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

파이썬의 return 문

<시간/>

return [expression] 문은 함수를 종료하고 선택적으로 표현식을 호출자에게 다시 전달합니다. 인수가 없는 return 문은 return None과 동일합니다.

위의 모든 예는 값을 반환하지 않습니다. 다음과 같이 함수에서 값을 반환할 수 있습니다. -

#!/usr/bin/python
Function definition is here
def sum( arg1, arg2 ):
   # Add both the parameters and return them."
   total = arg1 + arg2
   print "Inside the function : ", total
   return total;
# Now you can call sum function
total = sum( 10, 20 );
print "Outside the function : ", total
을 호출할 수 있습니다.

출력

위의 코드가 실행되면 다음과 같은 결과가 생성됩니다 -

Inside the function : 30
Outside the function : 30