Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

function and lambda in python

# Normal function, usually called function with name
def add(a,b):
  return a + b 

print(add(1,2)) # 3

# Lambda function, usually called anonymous function (without name)
add2 = lambda a,b: a+b
print(add2(1,2)) # 3

'''
Note:
If you want to use lambda with return value make a variable before : then
lambda's expression
= lambda x, y: x * y 

If you want to use lambda with no return, you don't need to write 
variable
= lambda: print("My name Lux") 

The way lambda program work is same as a function but without name. 
'''
Source by stackabuse.com #
 
PREVIOUS NEXT
Tagged: #function #lambda #python
ADD COMMENT
Topic
Name
9+1 =