Q:

how to do lambda in python

Lamda is just one line anonymous function
Useful when writing function inside function
it can take multiple arguments but computes only one expression

Syntax:
   x = lambda arguments : expression
5

lambda arguments : expression
7
#lambda can be also used for adding string 
>>> full_name = lambda first, last: f'Full name: {first.title()} {last.title()}'
>>> full_name('guido', 'van rossum')
'Full name: Guido Van Rossum'
3
# This is a normal function:
def Function(Parameter):
  return Parameter

# And this is a lambda function
Function=lambda Parameter : Parameter

"""

They are both completely identical and do the exact same job (which is
to take in a parameter and output it) the reason lambda functions exist
is to make code shorter and readable since a lambda function only takes
up one line.

Lambda functions are mostly used for simple things like what
I did whilst defining functions are used for complex things.

You do not
have to use lambda functions, it's all about preference.

"""
3
def myfunc(n):
  return lambda a : a * n
mytripler = myfunc(3)
print(mytripler(11)) 
5
Lamda is just one line anonymous function
Useful when writing function inside function
it can take multiple arguments but computes only one expression

Syntax:
   x = lambda arguments : expression
    
5
>>> def identity(x):
...     return x

These two functions do the same thing

>>> lambda x: x
1
lambda arguments: expression
0

New to Communities?

Join the community