Do all parameters have to be used within a function?


#1

Question

Will a function still work if there are parameters, but some of them are never used within the function itself?

Answer

Functions will still work as normal even if none of the parameters are actually used within the function code itself.

However, doing this may be counterintuitive, as the purpose of parameters is to allow different input values to be used when running a function to produce results based on the input. Not using some of the parameters means that although the input value must be provided in the function call, it’s not used, so it can be a waste of space or memory.

Example

# This function takes 3 parameters, but only uses 
# 2 of them in its code.
def add(a, b, c):
  return a + b

# The call still requires inputs for each parameter.
add_two(10, 30, 50) # returns 40