Can pure functions take an argument? For example,
def convert(n):
Thank you in advance
Can pure functions take an argument? For example,
def convert(n):
Thank you in advance
Of course they can have arguments. The only difference is whether they have side effects beyond the input and output parameters. Without input arguments to use as "inspiration", it's difficult for a pure function to do something useful.
Yes they can have arguments. Find some details below:
Pure functions: Functions have some input (their arguments) and return some output (the result of applying them). The built-in function:
>>> abs(-2)
gives the result:
2
No effects beyond returning a value.
Non-pure functions: In addition to returning a value, applying a non-pure function can generate side effects, which make some change to the state of the interpreter or computer. A common side effect is to generate additional output beyond the return value, using the print function.
print(1, 2, 3)
1 2 3