What is user defined function?
Special functions defined by the software developer to perform some pre-defined task by giving some name to a set of statements.
We can avoid the use of those statements again and again.
User defined functions are used to create the reusable code.
Python provides def keyword to define a function.
Function may or may not return some value. Python provides the return keyword to return some value.
Syntax 1
def functioname():
statements
Syntax 2
def functionname(arguments):
statements
Syntax 3
def functionname(arguments):
statements
return value
Example 1
Write the Python code having a function cube() that takes a number and prints the cube of that number
Problem: The current cube() function is not a reusable function.
Example 2
Create a function cube() that take a number and returns cube of that number.
Create another function volume() that takes radius of a sphere and returns volume of the sphere by using the cube() function

Comments
Post a Comment