Professional Documents
Culture Documents
Lambda Expression - 2019
Lambda Expression - 2019
Lambda Expressions
Dr. Wang Zhengkui
Lambda Expression
• An interesting syntax that lets you define one-line mini-functions on the fly
• Another way to create one function using lambda keyword
10
Comparison between def and lambda
def manner Lambda manner
def functionName (arg 1, arg 2, …, argn): lambda arg1, arg2, …, argn: expression
function body
return expression
• Start with a lambda keyword
• Start with def keyword
• Have no name , anonymous function
• A function with a given name
• The input arguments are followed after
• All the input arguments surrounded by
the lambda keyword
() after the function name
• Returned value is followed after “:”
• The function body starts after one “:”
• Only support one line computation
• A function can support complicated
function body • No return keyword
• Return one value with return keyword • Must return something
11
Lambda Expression - Examples
12
Lambda Expression - Examples
• Calculate the summation of all the numbers in one list using reduce
13
Python
• Continuous learning
• More information about Python programming:
–Python online Tutorial
–Free online Python books
14
Module Road Map
Wishful
Debugging & Selection &
Thinking Higher-order Lambda
DocString Iteration function Expression
Algorithms & Software Recursion
problem solving development
Class – Object-Oriented
Programming
Skills of IT
Objective Python Programming
Professional Covered in ICT1009
OOP
19