Functions in Python
Functions in Python
---------------------
Function: Function is a statement (or) group of related statements
which is used to perform specific task.
1. Built-in function
2. User defined function
1. Built-in function:
---------------------
--> These functions are available by default when we install python software.
Ex-: print()
type()
id()
len()
eval()
--> Return statements is used to return the result to the calling place.
--> Parameters, docstring, return statements are optional.
#Creating a Function
def f1():
print("Welcome to my programming world")
#Calling the declared function
f1()
def f1(name):
print("Hello", name)
f1("Sai")
f1("Bhabani")
def add(a,b):
print("Sum is:", a+b)
add(20, 10)
add(40, 30)
Return Statements-:
-------------------
--> When we call the function, function will perform some task and
we call the function and return the result value to the calling
place using return statement.
def add(a,b):
return a+b
print("Sum is:", add(20, 10))
print("Sum is:", add(40, 30))
Ans 1:
------
def sqr(a):
sqr = a*a
return sqr
x = sqr(10)
print("Square is:", x)
(Otherway)
def square(n):
x = n*n
return x
print("Square is:", square(10))
Question 2 -:
-------------
def even_odd(n):
if n % 2 == 0:
print(n, "is even number.")
else:
print(n, "is odd number.")
even_odd(8)
Question 3 -:
-------------
====================================================End of Python
Functions=======================================================