Python User Function Exercises

Let’s check out some exercises that will help understand “Defining Functions” better.

Exercise 16-a

Define a function named f_1 which will print "Hello World!"


The syntax for defining functions is:

def FunctionName ():

After your 1st line of function definition your statement needs to be indented either as:

  1. 1 Tab key
  2. 4 Space characters.
def f_1():
    print("Hello World!")

Exercise 16-b

Now define the same function f_1 and assign it to variable ans_1. See what happens.


The syntax for defining functions is:

def FunctionName ():

After your 1st line of function definition your statement needs to be indented either as:

  1. 1 Tab key
  2. 4 Space characters.
ans_1 = f_1()