Python Function

Function is a group of instructions for a specific purpose.

By making function you can use the code as many times as you want


Syntax

 # defining function
def function_name(parameter_list):
   statement_1
   statement_2
   
# Calling a function
function_name(parameter_list)


Example

  1. def scanftree(a, b):
  2. if a>b
  3. print a
  4. else
  5. print b # defining function
  6. scanftree(5,6) # Calling a function

Output

6

  1. def scanftree(a, b):
  2. if a>b:
  3. print a
  4. else:
  5. print b # defining function
  6. scanftree(5,6) # Calling function

In the next chapter you are going to learn file-IO in python