How to Connect Lambda in Python
The Python "Lambda" function lets you create anonymous functions that do not require a name during execution. For standard functions, the Python language requires a name, which is used when you call the function. With the Lambda feature, you create a function with no name on-the-fly to return a value to the user.
Instructions
-
-
1
Right-click the Python file you want to edit and click "Open With." Click your Python editor to open the file in the editor.
-
2
Create the lambda procedure. The procedure is associated with a Python variable. For instance, the following code connects to a lambda feature that adds 2 to any number:
g = lambda x: x+2
-
-
3
Connect to the lambda function and print the results to the screen. The following code prints "6" on the user's screen using the lambda anonymous function:
print g(4)
The "4" value is passed to the lambda function. The number two is added to the number, and the result is printed to the screen.
-
1