Anonymous Functions and lambda: lambda [arg1[, arg2, ... argN]]: expression : lambda « Function « Python Tutorial






def true():
    return True

def true(): return True

lambda :True
true = lambda :True
print true()

def add(x, y): return x + y  # lambda x, y: x + y
def usuallyAdd2(x, y=2): return x+y  # lambda x, y=2: x+y
def showAllAsTuple(*z): return z  # lambda *z: z

a = lambda x, y=2: x + y
print a(3)
print a(3,5)
print a(0)
print a(0,9)
b = lambda *z: z
print b(23, 'zyx')
print b(42)








10.11.lambda
10.11.1.If a function body is a single return expression statement, you may choose to replace the function with the special lambda expression form
10.11.2.The lambda operator creates anonymous functions: lambda args : expression
10.11.3.Using lambda Functions: define one-line mini-functions on the fly
10.11.4.A lambda function squares the members of a sequence:
10.11.5.Anonymous Functions and lambda: lambda [arg1[, arg2, ... argN]]: expression
10.11.6.Define variable used by lambda function outside
10.11.7.Lookup variable used in lambda
10.11.8.Applying Functions to Arguments