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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy