Linux

Python Special Functions

In this chapter we will discuss the special type of function of Python

Python Lambda Functions

Python supports the creation of anonymous functions (i.e. functions that are not bound to a name) at runtime, using a construct called Pythonlambdafunction
Syntax
lambda arg1 ,arg2,...argn : expression

Let us discuss the example.of Python lambda function
Python lambda function
Python lambda function
Click to view code
In next example you will see the use of Python lambda function .

Python filter()

Python filter() function give very stylish way to create filtered list.
Syntax
filter(function1, list1)

Here function1 returns true or false boolean value. Function function1 applies to all value of list list1 Only if function1 returns True then the element of the list1 will be included in the res list. Let us discuss the example of odd value from given list.
Python  filter(function1, list1) function
Python filter() function
Click to view code
Now let us see it Lambda version.
Python  filter(function1, list1) function
Python filter() function
Click to view code

Python map() function

The Python map() function used to map the value.
Syntax
map(function1, seq)

Each item from the seq (may be list ,tuple ) transfer to the function function1 and function map() return a list of new mapped value.
Let us see the example to map celsius to fahrenheit
Python  map(function1, seq) function
Python map(function1, seq) function
Click to view code




admin