0% found this document useful (0 votes)
7 views3 pages

Unit 4 PWP

The document discusses data type conversion functions in Python, highlighting implicit and explicit conversion methods with examples. It also covers functional programming concepts, including pure functions, lambda expressions, and built-in functions like map, filter, and reduce, illustrating their usage with code snippets. Overall, it emphasizes the importance of type conversion and functional programming in Python for effective coding practices.

Uploaded by

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

Unit 4 PWP

The document discusses data type conversion functions in Python, highlighting implicit and explicit conversion methods with examples. It also covers functional programming concepts, including pure functions, lambda expressions, and built-in functions like map, filter, and reduce, illustrating their usage with code snippets. Overall, it emphasizes the importance of type conversion and functional programming in Python for effective coding practices.

Uploaded by

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

Data Conversion Function In Python:

Introduction:
Data type conversion functions converts the Py-type data into another form of data. It is
a conversion technique. Implicit type translation and explicit type converter are
Python's two basic categories of type conversion procedures.
Python has type conversion routines that allow for the direct translation of one data
type to another. This is very helpful for competitive programming as well as routine
programming
Eg1:
b=25
a=float(b)
print(a)#output will be 25.0

c=str(b)
print(c)#output will be 25

d=bin(b)
print(d)#output will be 0b11001

o=oct(b)
print(o)#output will be 0o31

print(ord('A')) #will return ASCII value of A.


print(chr(90)) #will return Z because 90 is ASCII of Z..

Eg2:
x = 'javaTpoint'
y = tuple(x)
print ("tuple: ",end="")
print (y)
y = set(x)
print ("set: ",end="")
print (y)

y = list(x)
print ("list: ",end="")
print (y)

Output:

tuple: ('j,' 'a', 'v,' 'a', 'T,' 'p,' 'o', 'i', 'n,' 't')
set: {'n,' 'o', 'p,' 'j,' 'v,' 'T,' 'i', 'a', 't'}
list: ['j,' 'a', 'v,' 'a', 'T,' 'p,' 'o', 'i', 'n,' 't']

Functional Programming module in Python


Functional programming is a programming paradigm in which we try to bind everything in a
pure mathematical functions style. It is a declarative type of programming style. Its main
focus is on ” what to solve” in contrast to an imperative style where the main focus is “how to
solve“. It uses expressions instead of statements. An expression is evaluated to produce a
value whereas a statement is executed to assign variables.
Concepts of Functional Programming
Any Functional programming language is expected to follow these concepts.
Pure Functions: These functions have two main properties. First, they always produce the
same output for the same arguments irrespective of anything else. Secondly, they have no
side-effects i.e. they do modify any argument or global variables or output something.
1.Lambda expression:
This function can take any number of argument ,but can only have one expression.
Syntax:
lambda arguments:expression
EX:
X=lambda a,b:a+b
Print(x(5,6))
Op- 11
EX2:
def myfun():
a=lambda a:a*n
myfun(2)
print(a(11))
OP-11

2.Map(): The map() function executes a specified function for each item in
an iterable. The item is sent to the function as a parameter.
Syntax
map(function, iterables)
Eg:
def add(n):
return n+n
num=(1,2,3,4)
result=map(add,num)
print(list(result))

3. filter()
The filter() method filters the given sequence with the help of a function that tests each element in
the sequence to be true or not.
Eg 1:
ages=[5,12,20,18,24]
def my(x):
if x>18:
return True
else:
return False
adults=filter(my,ages)
print(list(adults))

4. reduce():
The reduce(fun,seq) function is used to apply a particular function passed in its argument to all of
the list elements mentioned in the sequence passed.
Eg1:
from functool import reduce
numb=[1,2,3,4]
r=reduce(lambda x,y: x*y, numb)
print(r)

You might also like