''' 20210930 Robin Dawes Using *args and using default values for parameters ''' # the parameter name *args could be *, such as *values, *words, *pizza, or whatever you like def fun_1(*args): '''prints out its arguments parameter: *args - any number of arguments of any types ''' print("\nThese are the arguments given") for a in args: print('\t',a) fun_1("This","works") fun_1("So","does","this") fun_1() def fun_2(x, *args): '''demonstrates that we can combine named parameters and *args this requires at least one argument value ''' print("\nx =", x) print("There are",len(args),"other arguments") # show that args is a tuple if type(args) is tuple: print("args is a tuple") else: print("args is not a tuple") print(args) fun_2(3,4,5,6) # this would fail: # fun_2() def fun_3(x, y, name="anonymous"): '''demonstrates the use of a default value for a parameter This makes 'name' an optional parameter. If we call this function without explicitly passing a value for 'name', the default value is used ''' print("\nname:", name) print("x:", x,"\ty:", y) # calling the function with a value for the optional parameter fun_3(17, 82, name = "Brady") # calling the function without giving a value to the optional parameter fun_3(16, 32)