Return statement:
#example program for return
statement
def add(a,b):
return(a+b)
d=add(5,4)#function call,
return value is stored in d
print(d)
function can take input values
as parameters and executes logic, and returns output to the function call with
return statement.
#example program for return
statement
def prime(n):
ctr=0
for i in range(1,n+1):
if n%i==0:
ctr+=1
if ctr==2:
print(n,"is prime")
else:
print(n,"is not prime")
"""output:
>>> prime(3)
3 is prime
>>> prime(4)
4 is not prime
>>> prime(6)
6 is not prime
>>>
""""
Assignment function that generates prime
numbers:
10
2,3,5,7,11,13,17,19,23,29
Related video: https://youtu.be/EpizFbmfC5s
Prev Calling a function
Next: A function return more than one value
Related videos: https://youtu.be/SIwAaHwKctY
Sir please give me soft copy
ReplyDelete