I'm defining a function with some kwargs. I know having an undefined variable as a kwarg default value throws an error. For example:
# This is fine
def foo(word='Ni!'):
print(word)
foo()
> Ni!
# This won't work
def foo(word=it):
print(word)
it = 'Ni!'
foo()
> (gives an error)
But is there some way to use the keyword of a kwarg itself as the default value variable name, with the expectation that it will have been defined by the time the function is called?
# This is what I want
def foo(word=word):
print(word)
word = 'Ni!' # Note it's defined after function definition, but before function call
foo()
> Ni!
(I'm having trouble searching for answers to this, apologies if it's answered somewhere already!)