Lambda Function
Lambda function does not have any name like user-defined functions. It takes n number of arguments but it can have only one expression.
Example:
x = lambda a : a + 10
print(x(5))
Output:
10
Map Function:
Map function iterates on iterable elements without using loops and executes the specified function for each element.
Example:
def add(n):
return n + n
numbers = (1,2,3)
result = map(add, numbers)
print(list(result))
Output:
[2, 4, 6]
Zip Function:
It is used to return zip object which contains the iterator of tuples having the same indexed items of each passed iterable is paired together.
Example:
a = ("Ali", "Zahid", "Zain")
b = ("Ali", "Sohail", "Sajid")
x = zip(a,b)
print(list(x))
Output:
[('Ali', 'Ali'), ('Zahid', 'Sohail'), ('Zain', 'Sajid')]
No comments:
Post a Comment