PYTHON PROGRAMMING
(PYTHON 3.X using Jupyter Notebook)
Advanced Function
DSC551 – PROGRAMMING FOR DATA SCIENCE
Pn Marhainis Jamaludin
Faculty of Computer and Mathematical Sciences
Functions in Python
1. Function with keyword arguments
• Function can be called by passing parameter values using the
parameter names in any order
2. Unknown number of arguments (*)
• You use * to indicate that we do not know how many parameters the
user is going to pass to this function
3. Single parameter prefixed with (**)
• If you are using the name of arguments or parameters, the number of
parameters passed is not defined.
Functions with Keyword arguments
Unknown Number of Arguments (*)
Single parameter prefixed with (**)
Lambda Function
• Anonymous function – having no function name
• Small function usually not more than 1 line
• To be assigned to a variable since it does not have any name.
• Syntax
lambda arguments : expression arguments
• Comparing the def function and lambda function
Examples:
Map function
• Executes a specified functions for each item in
iterable.
• Map function applies the function to all the
elements of the sequence.
• Syntax:
map(function, iterables)
Reduce Function
• Similar to map function, but, reduces a list to a
single value by combining elements via a supplied
function.
• This function is in functools module, need to
import from this module
from functools import reduce
Filter Function
• Test each element in sequence to be True or False
References
• https://www.programiz.com/python-
programming/list
• https://www.digitalocean.com/community/tutorial
s/understanding-lists-in-python-3