Skip to content

Exercise 7.1: Optional parameters

Alternative course

Function parameters

Function parameters can be optional. This means that when calling a function, you have the option to set the variable or not.

A function with an optional parameter may be called in multiple ways:


To make a variable optional, add =None to the parameter.

Type the program shown below and run it:

def addNumbers(a,b, c=None):

    if c is not None:
        return a+b+c
        return a+b

print( addNumbers(2,3) )
print( addNumbers(2,3,4) )

Study drill

Try the exercises below

1. Create a function that can be called in these ways:


After completing these continue with the next exercise.


Exercise 7: Functions
Exercise 8: Lists
Published inUncategorized

Be First to Comment

    Leave a Reply