Python- How does return work in function -


i confused using functions in python.

suppose have code

def calculate(a):     = int(a)     return  # or yield 

then write as

def _convert(a):     = int(a)     return # or yield a+1  def calculate(a):     _convert(a)  # correct or need (return _convert(a)) 

-- internal return function goes till end?

the return statement allows determine value function call takes in expression. if 1 function calls another, the second functions returns value first.

thus in second example, in order calculate return value caller must indeed use return statement, , return _convert(a) indeed correct.

such answers can determined running them in interactive interpreter, encourage beginners use purpose.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -