lambda python explain code example
Example 1: lambda condition python
f = lambda parameter : exp1 if cond else exp2
# example
f = lambda x: "even" if x%2==0 else "odd"
Example 2: python function vs lambda
>>> a = lambda x : 1 + x
>>> a(5)
6
f = lambda parameter : exp1 if cond else exp2
# example
f = lambda x: "even" if x%2==0 else "odd"
>>> a = lambda x : 1 + x
>>> a(5)
6