Functions in Python
Here we wil learn about Functions in python.
Functions in Python
A function is a collection of connected statements that accomplishes a single purpose. Functions assist in segmenting our program into manageable, modular portions. Our program becomes more organized and controlled as it gets bigger and bigger. It also makes the code reusable and prevents repetition.
name = " Anisha"
print(len(name))
def add_two(a,b):
return a+b
print(add_two(3,4))
def called():
print("Hello anisha")
called()
def three(a,b,c):
return (a+b+c)
print(three(2,3,4))
def odd_even(num):
if num % 2 == 0:
return "even"
else:
return "odd"
print(odd_even(9))
def fibo(n):
a = 0
b = 1
if n == 1:
print (a)
elif n == 2:
print (a,b)
else:
print (a,b,end = " ")
for i in range(n - 2):
c = a+b
a=b
b=c
print(b, end = " ")
fibo(10)