🐍 Did you know you can create a quick anonymous one line function? Yes. It is called Lambda Expression. Why would you need lambda? Sometimes you want to use a function just once and never again for a simple task that ends in one line, such as for sorting, that's when lambda expression comes to use.
print(sqr(10))
Syntax of lambda expression
<variable> = lambda <input_variable>: <expression>Example
sqr = lambda num: num**2print(sqr(10))
Comments
Post a Comment