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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -