0% found this document useful (0 votes)
4 views

Functions

Uploaded by

yalluhavaldar2
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)
4 views

Functions

Uploaded by

yalluhavaldar2
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/ 2

#Proprietary content. ©Great Learning. All Rights Reserved.

Unauthorized use or distribution prohibited

def hello():
print("Hello World")

hello()

Hello World

#Function with parameter

def add10(x):
return x+10

add10(10)

20

def even_odd(x):
if x%2==0:
print(x, " is even")
else:
print(x, " is odd")

even_odd(5)

5 is odd

#lambda functions

g = lambda x: x*x*x
print(g(7))

343

#lambda functions with filter


li = [5, 7, 22, 97, 54, 62, 77, 23, 73, 61]
final_list = list(filter(lambda x: (x%2 != 0) , li))
print(final_list)

[5, 7, 97, 77, 23, 73, 61]

#lambda functions with map


li = [5, 7, 22, 97, 54, 62, 77, 23, 73, 61]
final_list = list(map(lambda x: x*2 , li))
print(final_list)

[10, 14, 44, 194, 108, 124, 154, 46, 146, 122]

from functools import reduce


li = [5, 8, 10, 20, 50, 100]
sum = reduce((lambda x, y: x + y), li)
print (sum)

193

You might also like