Python 3: Change default values of existing function's parameters?
You can define a special version of print()
using functools.partial()
to give it default arguments:
from functools import partial
myprint = partial(print, end='-', sep='.')
and myprint()
will then use those defaults throughout your code:
myprint(a)
myprint(b)
myprint(c)
You can also use a lambda function:
my_print = lambda x: print(x, end='-', sep='-')
my_print(a)
my_print(b)
my_print(c)
There is also a method that allows multiple parameters and works with lambdas:
my_print = lambda *args: print(*args, end="-", sep=".")