Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

ICT1002 PROGRAMMING FUNDAMENTALS

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

• Given a list of numbers, calculate the squares of each item

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

Input/output & data


Knowledge of Tools/Rules Elements of Functional
Computer programming abstraction formatting
Knowledge (From keyboard;
Variables & Types & Operators &
of Software
Advanced Data Structures From files)
Fundamental concepts of computer programming
18
ICT1002 18 W2
About Project
• Reserve sufficient time for your program integration and
debugging
• Please submit the report, video and source code to LMS
• About the video:
– Part 1: Introduce your system
– Part 2: System Demo

19

You might also like