python - can lambda have more than one return -


i know lambda doesn't have return expression. normally

def one_return(a):     #logic here     c = + 1     return c 

can written:

lambda : + 1 

how write 1 in lambda function:

def two_returns(a, b):     # logic here     c = + 1     d = b * 1     return c, d 

yes, it's possible. because expression such @ end of function:

return a, b 

is equivalent this:

return (a, b) 

and there, you're returning single value: tuple happens have 2 elements. it's ok have lambda return tuple, because it's single value:

lambda a, b: (a, b) # here return implicit 

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -