Python Lambda Function Example

In the example, we defined a lambda function(upper) to convert a string to its upper case using upper().

This code defines a lambda function named upper that takes a string as its argument and converts it to uppercase using the upper() method. It then applies this lambda function to the string ‘w3wiki’ and prints the result

Python3




str1 = 'w3wiki'
 
upper = lambda string: string.upper()
print(upper(str1))


Output:

w3wiki

Python Lambda Functions

Python Lambda Functions are anonymous functions means that the function is without a name. As we already know the def keyword is used to define a normal function in Python. Similarly, the lambda keyword is used to define an anonymous function in Python

Similar Reads

Python Lambda Function Syntax

Syntax: lambda arguments : expression This function can have any number of arguments but only one expression, which is evaluated and returned. One is free to use lambda functions wherever function objects are required. You need to keep in your knowledge that lambda functions are syntactically restricted to a single expression. It has various uses in particular fields of programming, besides other types of expressions in functions....

Python Lambda Function Example

In the example, we defined a lambda function(upper) to convert a string to its upper case using upper()....

Use of Lambda Function in Python

...

Practical Uses of Python lambda function

Let’s see some of the practical uses of the Python lambda function....

Using lambda() Function with filter()

...

Using lambda() Function with map()

...

Using lambda() Function with reduce()

Python Lambda Function with List Comprehension...

Contact Us