Python Anonymous/Lambda Function

Опубликовано: 04 Сентябрь 2020
на канале: Sipun Tarai
72
8

#PythonProgram
#CodeWithSipun
#PythonAnonymous/LambdaFunction


Python Anonymous function (Lambda function):-
These functions are not declared in standard manner by using def
keyword.
We can use lambda keyword to create small anonymous function
Lambda forms can take any number of arguments but return just
1 value in the form of an expression.
They cannot contain multiple expression.
An anonymous function cannot be a direct call to print because
lambda requires an expression.
Lambda function have their own local namespace and cannot
access variables other than those in their parameter list and
those in the global namespace.
Although it appears that lambdas are a one line version of a
function but they are not equivalent to inline statements in C and
C++ whose purpose is to stack allocation by passing function
during invocation for performance reasons
Syntax:-
lambda [arg1 [,arg2,....,argn]]:expression
Example:-def square(a): #Normal function is used
return a*a
sqr=lambda a:a*a #anonymous function
print("Square of number is",square(12))
print("Square of number is",sqr(11))
Output:-
Square of number is 144
Square of number is 121


На этой странице сайта вы можете посмотреть видео онлайн Python Anonymous/Lambda Function длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Sipun Tarai 04 Сентябрь 2020, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 72 раз и оно понравилось 8 зрителям. Приятного просмотра!