[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Python scope question


On 13/03/19 3:38 AM, Arup Rakshit wrote:
> I have questions how nonlocal and global affecting the variable assignment. Also how each print statement looking up the values for the spam variable. This scope thing in python is very confusing too me still. Can anyone help me to understand this code w.r.t to scope in Python?
> $ python3
> After local assignment: test spam
> After nonlocal assignment: nonlocal spam
> After global assignment: nonlocal spam
> In global scope: global spam

Think this will help.

Watch the scopes 'appear' and operate in front of your very eyes:


Regards =dn