DEV Community

Ajith R
Ajith R

Posted on

5 powerfull function in python

Lambda Function:
It is known as anonymous function.
If you have a single operation to be executed,then the lambda function is extremely useful intead of declaring a traditional function using def keyword.

Python Lambda Function

answer = lambda a, b : a*2 + b2 + 2(a+b) print(answer(3,6))

Output: 63

Map Function:

The map function executes a specified function for each item in an iterable. The Iterable element is sent to the function as a parameter. You can also use a lambda function inside the map.

Python Map Function

def addList(a,b):
return a+b

res = list(map(addList, [2, 6, 3],[3, 4, 5]))
print(res)

Output: [5, 10, 8]

Filter Function:

The filter is a built-in function, which is useful when it required to segregate any kind of data. It is used to extract or filter the data based on the given condition.

Python filter Function

def isPositive(a):
return a>0

res = list(filter(isPositive, [2, 6, 3, -1, -7]))
print(res)

Output: [2, 6, 3]

Zip Function:

zip() function creates an iterator that will aggregate elements from two or more iterables.

You can use the resulting iterator to quickly and consistently solve common programming problems, like creating dictionaries.

Python zip Function

user_id = [10, 11, 12] user_name = ['Mike', 'John', 'Nick']
user_Info = list(zip(user_name, user_id)) print(user_Info) # Output:

[('Mike',10),('John',11),('Nick',12)]

Help Function:
The Python help function is used to display the documentation of modules, functions, classes, keywords, etc.
If the help function is passed without an argument, then the interactive help utility starts up on the console.

Python help Function

Displaying the docs for print keyword

print(help(print))

Output :

"""print(...)
print(value,..., sep='end='\n',file-sys.stdout,flush=False)

Top comments (0)