Function [six] Anonymous functions Anonymous functions

Anonymous function

 

Anonymous function:

  • 1, lambda keyword
  • 2, x representative of the function parameter;
  • 3, x + 1 is equivalent to the return value of the function representing a return, the results need to return a plurality of columns in parentheses: the lambda X, Y, Z: (X +. 1,. 1 + Y, + Z. 1)
  • 4, no names need to be defined;
def fun(x):
    return x+1
print(fun(10))

fun = lambda x:x+1
print(fun(10))

Anonymous function:

  • 1, lambda keyword
  • 2, x representative of the function parameter;
  • 3, x + 1 is equivalent to the return value of the function representing a return, the results need to return a plurality of columns in parentheses: the lambda X, Y, Z: (X +. 1,. 1 + Y, + Z. 1)
  • 4, no names need to be defined;
def fun(x):
    return x+1
print(fun(10))

fun = lambda x:x+1
print(fun(10))

Guess you like

Origin www.cnblogs.com/youxiu123/p/11480664.html