Function that we define ourselves to perform a specific task are called user defined functions .
These functions are created using def keyword , inside the function we write any statement with the indentation (4 spaces ) . The def keyword , then function name and round brakets after that .
When we need to call our function we have to use function name with round brackets(). When we will call the function , statement of function body will be executed . This will be not be executed untill we call that .
For exapmle:
def animal():
print “Hi Guys welcome to the python world”
animal()
>> output would be : Hi Guys welcome to the python world
Advantages of user defined functions
1. User defined functions help to decompose a large programs into small segments .
2. When we are working on large project , that time this divide the workload by making small – small functions .
# Find the below exapmle for user defined function
def addition(x, y):
add=x+y
return add
num1=float (input(“Enter the number 1: “))
num2=float(input(“Enter the number 2: “))
print (“sum is “ , addition(num1, num2))
output would be ;
>> Enter the number 1: 30.0
>> Enter the numberb 2: 20.5
>> sum is 50.5
* In the above example addition() is the user defined function and intput(), print() and float() are the builtin functions of python .
softcrayons tech solutions is a best python training institute in vasundhra ghaziabad.
These functions are created using def keyword , inside the function we write any statement with the indentation (4 spaces ) . The def keyword , then function name and round brakets after that .
When we need to call our function we have to use function name with round brackets(). When we will call the function , statement of function body will be executed . This will be not be executed untill we call that .
For exapmle:
def animal():
print “Hi Guys welcome to the python world”
animal()
>> output would be : Hi Guys welcome to the python world
Advantages of user defined functions
1. User defined functions help to decompose a large programs into small segments .
2. When we are working on large project , that time this divide the workload by making small – small functions .
# Find the below exapmle for user defined function
def addition(x, y):
add=x+y
return add
num1=float (input(“Enter the number 1: “))
num2=float(input(“Enter the number 2: “))
print (“sum is “ , addition(num1, num2))
output would be ;
>> Enter the number 1: 30.0
>> Enter the numberb 2: 20.5
>> sum is 50.5
* In the above example addition() is the user defined function and intput(), print() and float() are the builtin functions of python .
softcrayons tech solutions is a best python training institute in vasundhra ghaziabad.
No comments:
Post a Comment