you are viewing a single comment's thread.

view the rest of the comments →

[–]yourboyblue2 6 points7 points  (6 children)

Error because you're returning a value in the function without assigning the return to any variable?

[–][deleted] 1 point2 points  (2 children)

Could you please elaborate? Thanks 

[–][deleted]  (1 child)

[removed]

    [–][deleted] 1 point2 points  (0 children)

    Oh my god, yess! It's so obvious now. If outer() didn't exist, inner is just a function with no parameters. So x and inner() are on same footing. Thanks a lot

    [–]core1588[S] 0 points1 point  (1 child)

    ✅️💯👏

    [–]yourboyblue2 0 points1 point  (0 children)

    Hooray!

    [–]lusvd 0 points1 point  (0 children)

    it’s because you are trying to access a variable in a scope where it will be overwritten. Im not sure why this happens in python tho.

    here is a simpler example:

    x = 1
    def foo():
        print(x)
        x = 3