python - Why does this not identify the variable s? -
this question has answer here:
- python nested function scopes 3 answers
- python nested functions variable scoping 10 answers
consider python code:
def lower_it(s): def charr(): s = s.lower() #error ans = s return ans return charr() the place have written #error gives error because says s referenced before assignment. don't think should give error because if call function lower_it('hello'), should make s = 'hello' , s in scope of charr, right? variable defined in body of lower_it should in scope of charr, right?
Comments
Post a Comment