New rules for scope in a function?
Ben Bacarisse
ben.usenet at bsb.me.uk
Mon Feb 18 16:04:02 EST 2019
"Steve" <Gronicus at SGA.Ninja> writes:
> OK, I wrote:
>
> x = "A"
> print("x = " + x)
>
> def f(y):
> print("x= " + x + " y= "+ y)
>
> f(x)
>
> and it worked, inspite of what I was seeing in my own program.
> How quick I am to blame Python. (:
> When I isolate my function that stumped me, I will post it.
This small variation might point the way. If you can explain it, you'll
be most of the way there.
x = "A"
print("x = " + x)
def f(y):
x = "B"
print("In f, x = " + x + " y = "+ y)
f(x)
print("x = " + x)
<cut>
The material I cut did include the explanation so go back and read the
message you replied to here if you don't follow.
--
Ben.
More information about the Python-list
mailing list