Function is a re-usable piece of code which can be called with arguments.
# define a function with name foo
# all lines indented with respect to next line form the body of this function
def foo (var1, var2):
if (var1 == var2):
print ("var1 equals var2")
elif (var1 < var2):
print ("var1 < var2")
print ("var1 > var2")
# function foo can be called as follows:
var1 < var2
# If function was called as:
# Then output would have been
var1 > var2
Note: The copy paste from the above may remove the indentation spaces due to which python can give indentation errors.
If such a thing happens, then indentation spaces have to be put manually after copy-paste.
Got a thought to share or found a bug in the code? We'd love to hear from you: