Issue
Assuming the following snippet:
a = None
def set_a():
global a
a = 10+2
print(a)
The result is expected to be 12
, so why does it remain as None
and won't update?
I've been looking for similar questions on stackoverflow but didn't find a proper explanation/solution. How exactly can I access the modified value of a global variable which has been updated inside a function from outside of it?
Any help is appreciated in advance.
Solution
>>> a = None
>>>
>>> def set_a():
... global a
... a = 10+2
...
>>> set_a()
>>>
>>> print(a)
12
Answered By - Halley Oliveira
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.