0

Can pure functions take an argument? For example,

def convert(n):

Thank you in advance

Tina
  • 1
  • 3
    It would make no sense for a pure function to take no arguments – Francisco Nov 04 '16 at 22:06
  • 1
    @FranciscoCouzo: https://xkcd.com/221/ ;-) – NPE Nov 04 '16 at 22:07
  • Pure functions are those that don't have side effects. They don't change anything in the process of doing their work (e.g., no printing, no changing mutable objects, etc.). Their arguments are their complete inputs and their return value is their complete output. – kindall Nov 04 '16 at 22:07

2 Answers2

2

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.

Prune
  • 76,765
  • 14
  • 60
  • 81
0

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
Bobby
  • 1,585
  • 3
  • 19
  • 42
anati
  • 264
  • 2
  • 13