Is it possible to call a nested function defined inside an existing function:
For example:
def first(x):
def second():
print(x)
return second
I know I can do something like this: first(10)()
Yet I want to do something similar to this:
first(10).second()
My thinking is that it is not possible because second does not exist until first is called.
Am I right?
seconddoesn't exist outsidefirstscope. Consider using a class insteadsecond(), but why not makefirst()a class to begin with? (Example:def first(x): return str(x), thenfirst(10).upper()would work, because strings have a method namedupper()).