Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Lambda Functions

# The lambda keyword in Python provides a
# shortcut for declaring small and 
# anonymous functions:

add = lambda x, y: x + y
print(add(5, 3))

# Output
# 8

# You could declare the same add() 
# function with the def keyword:

def add(x, y):
	return x + y
print(add(5, 3))

# Output
# 8

# So what's the big fuss about?
# Lambdas are *function expressions*:

print((lambda x, y: x + y)(5, 3))

# Output
# 8


# • Lambda functions are single-expression 
# functions that are not necessarily bound
# to a name (they can be anonymous).

# • Lambda functions can't use regular 
# Python statements and always include an
# implicit `return` statement.
Source by www.revista-programar.info #
 
PREVIOUS NEXT
Tagged: #Lambda #Functions
ADD COMMENT
Topic
Name
4+6 =