Python Lambda | |||
| |||
A lambda function is a small anonymous function. A lambda function can take any number of arguments, but can only have one expression. Syntax
The expression is executed and the result is returned:
Lambda functions can take any number of arguments:
Summarize argument a, b, and c and return the result:
Why Use Lambda Functions? The power of lambda is better shown when you use them as an anonymous function inside another function. Say you have a function definition that takes one argument, and that argument will be multiplied with an unknown number:
Use that function definition to make a function that always doubles the number you send in:
Or, use the same function definition to make a function that always triples the number you send in:
Or, use the same function definition to make both functions, in the same program:
Below YouTube content is also helpful for better understanding Tags: Python Python Lambda | |||
| |||
| |||
|
OTHER POSTS IN THE SAME CATEGORYMastering Excel Data Manipulation with PythonTry...Catch Helps Ignoring Data Type Miss-Match Error in PythonRegExp example in Python to exclude javascript from HTML codePython code to convert from Lunar to SolarPython example to download webpagePython Tutorials for AP Computer Science Principles, Data Projects and High School InternshipPython ModulesPython ScopePython PolymorphismPython IteratorsPython InheritancePython Classes/ObjectsPython ArraysPython FunctionsPython While Loops/For LoopsPython Conditions and If statementsPython DictionariesPython SetsPython TuplesPython Comparison OperatorsPython Arithmetic OperatorsPrinting string n timesString concatenation by join()Python ListsPython String OperationsPython Data TypesPython VariablesPython Comments |