Python Lambda Function

Python Lambda Function

Lambda Function

  • It is the function which have no name like normal function
  • It can have number of argument
  • It have only one expression
  • It may or may not return a expression


Syntax

lambda arguments: expression

It return a value to a variable, when we assign as:

var =  lambda arguments: expression


Example1:

test = lambda y: y * 3

print(test(3)) # 9 is the answer


Example2:

square = lambda y: y * y

print(square(4)) # 16 is the answer


Example3:

show_name = lambda name: print('Hi ', name)

show_name(“Rushikesh”)


Anonymous Function In Python

Anonymous Function

oTo Create a Anonymous Function, We Have To Create a Lambda Function Without Assigning It To a Variable.

oAnonymous Function Have No Name To Call

oAnonymous Function Called a Lambda Function, But Every Lambda Function Is Not Anonymous Function

oIt Can Be Call Once


Example:

(lambda x: x + 2)(2)

print((lambda x: x + 2)(2))




To view or add a comment, sign in

More articles by Rushikesh J.

  • Linux Operating System

    Linux Operating System ======================= => Linux is a community based OS => Linux is free & Open Source => Linux…

  • Infrastructure

    ================= Infrastructure ================= Servers (Machines) Databases Storage Network Security Backup =>…

  • Application Architectural Patterns

    =================================== 1) Monolithic Architecture (Outdated) 2) Microservices Architecture (Trending)…

  • DevOps Introduction

    =============== What is DevOps =============== DevOps = Development + Operations => DevOps is a culture/process in IT…

    2 Comments
  • Try and Exception in Python

    Exception is the error and is an event, which occur when program statements are executing. It disrupts the flow of…

  • Python Array With Examples

    Array in Python Array in Python Array is the collection of items having same data type with contiguous memory location.…

  • Python Date Object

    We can work with time and date with Python. There are two module in Python time and datetime that used to work with…

  • String Formatting WITH Problems and Solution

    What is String Formatting? It is the way to insert custom string or variable in a text (string). Using string…

  • SET Different Methods With Examples

    SET Method : add() Working: This method is used to add element to set. Syntax: set.

  • Python SET Comprehension With Examples

    What is Comprehension? •We create a sequence from a given sequence is called comprehension. •Sequence means list…

Insights from the community

Others also viewed

Explore topics