I recently working on a statement question… So it asked me to list at least 2 examples of useful things a function can do without having a return statement. I know I can still output the result of the function if I use a variable to store it but what kind of advantage will it brought?
I think it is asking what are two ways a function can still be useful even if it doesn’t return anything.
So a function can still take in data and mutate it if it mutable, such as lists or objects but can’t change a string, and it will still be seen outside of the function.
It can still have an output, it just isn’t returned to what called it, such as writing to a file.
It could be used to change the state of a specific item, such as enabling or disabling something.
In essence they can still have side effects, so the work done in the function can still be observed/used outside of it without it being directly returned. So there are many more than those examples.