Convert python code into lambda function

0 votes

How do I convert the following python code into a lambda function?

def add(x, y): 
    return x + y
  
# Call the function
add(2, 3)  # Output: 5
May 23 in Python by Kiran
26 views

1 answer to this question.

0 votes

This should work:

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

In lambda x, y: x + y; x and y are arguments to the function and x + y is the expression which gets executed and its values is returned as output.

answered May 23 by Payal

Related Questions In Python

0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
610 views
0 votes
1 answer

Python: Lambda function in List Comprehensions

The first one create a single lambda ...READ MORE

answered Aug 27, 2018 in Python by Priyaj
• 56,200 points
138 views
0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 12, 2018 in Python by Priyaj
• 56,200 points
382 views
0 votes
1 answer

Convert string list of dict from csv into JSON object in python

You can use the ast module Ex: import ast s = """[{'10': ...READ MORE

answered Sep 24, 2018 in Python by Priyaj
• 56,200 points
60 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 168 views
+4 votes
6 answers
0 votes
1 answer

How to Convert usual text to executable machine code in python

what you are looking for is a ...READ MORE

answered Oct 1, 2018 in Python by Priyaj
• 56,200 points
33 views
0 votes
1 answer

I'm using Python 2.7 to convert an XML response (from a REST call to Atlassian Fisheye) into an HTML table.

You don't have a template matching tabularQueryResult in your ...READ MORE

answered Oct 4, 2018 in Python by Priyaj
• 56,200 points
30 views