Functions in Python
We can use User Defined Functions in Python like other Programing Languages.
def sayHello() :
print("Hello")
def sayHi(nm):
print("Hi ",nm)
def getTotal(x,y):
z=x+y
print("Total ",z)
def getMax(x,y):
if x>y :
return x
else:
return y
#Recursion
def fact(n):
if n==0:
return 1
else:
return n* fact(n-1)
sayHello()
sayHi("Jadeja")
getTotal(3,5)
getTotal(4.2,4.5)
getTotal("A","B") #Concate
z=getMax(4,6)
print("Max is ",z)
f=fact(6)
print("Factorial ",f)
Output for the above Python Example is:
Hello
Hi Jadeja
Total 8
Total 8.7
Total AB
Max is 6
Factorial 720
>>>