Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
21 views

(8a) Python - Advanced Function

Uploaded by

anis hannani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

(8a) Python - Advanced Function

Uploaded by

anis hannani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

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

You might also like