Passing a List in a Function in Python

Passing a List in a Function in Python

Not only variables but a list can also be passed and manipulated in a Python’s function. If you want to read about function read the post     User Defined Functions in Python and want to know about
list see post    List in Python . Further, I will demonstrate how to pass a list as a parameter and will return a list which has cube of passed list’s numbers.

def makecubelist(ls):
newls=[]
for i in ls:
newls.append(i**3)
return newls
ls=[3,4,5,6]
res=makecubelist(ls)
print(res)

See the program and output of the below program.

 

Passing a List in a Function in Python

Leave a Comment

Your email address will not be published. Required fields are marked *

©Postnetwork-All rights reserved.