0

I have a nested function that tries to modify a local var of its parent: (expected 70 15 got 70 70)

def foo() -> None:
    x = 70
    def readme() -> None:
        print(x)
    def writeme(y: int) -> None:
        # global x <----- this doesn't help either
        x = y    # <----- this doesn't work
    readme()
    writeme(15)
    readme()

I added the global keyword to indicate this variable already exists in some outer scope, but that didn't help. Note that this is different from this so question.

OrenIshShalom
  • 4,294
  • 5
  • 22
  • 55

0 Answers0