Junior — Middle
In what cases should parameters be used when calling a function?
sobes.tech AI
Answer from AI
Parameters when calling a function are used to pass data into the function so that it can work with different values without changing its code. This allows the function to be universal and reusable. For example, if you need to write a function that adds two numbers, parameters allow you to pass any numbers each time you call it:
def add(a, b):
return a + b
result = add(3, 5) # returns 8
Without parameters, the function would be limited to specific values, reducing flexibility and ease of use.