python anonymous function

Use anonymous function:

MINIMUM = lambda x,y :  (x > y) * y + (x < y) * x

print MAXIMUM(10,20)

 

Equivalent to using the function:

def MINIMUM(x,y):

  return  (x > y) * y + (x < y) * x

print MAXIMUM(10,20)

 

Reference: https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/0013868198760391f49337a8bd847978adea85f0a535591000

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324694614&siteId=291194637