I understand how it's work, but how I can do that python print true and false in this case?)
def f(func, value):
global a
a = 2
print(func(value))
a = 3
f(lambda x: x == a, 3)
f(lambda x: x == a, 2)
I understand how it's work, but how I can do that python print true and false in this case?)
def f(func, value):
global a
a = 2
print(func(value))
a = 3
f(lambda x: x == a, 3)
f(lambda x: x == a, 2)
If your goal is to have the code check the value of a
that you originally declared (i.e. 3) so that it prints True
;False
instead of the inverse, just don't set a
to 2 inside your function:
def f(func, value):
print(func(value))
a = 3
f(lambda x: x == a, 3)
f(lambda x: x == a, 2)
Using global
is generally not recommended because it makes it very easy to confuse yourself by having values change in unexpected ways.