this question has answer here:
- function not changing global variable 3 answers
how code below give output none?
def funct(x): x=7 x=11 x=test(x) print(x)
here code snippet:-
def func(): print (x) x = 90 x = 1 func()
the output should 90! scope searched local ,enclosed , global ,build-in .either x should here searched local or global please explain.
x
here not global variable in scope of functions, functions naturally create own namespaces, not include outer variables not passed in parameter.
there many issues code, including order of function calling, , order of operations inside functions; answer question in broadest way possible, in order access x
variable defined outside of functions, in greater scope is, need reference namespace, prepending global x
inside body of each of functions.
read on python variables , scope, , recheck other errors in code have stated above.
Comments
Post a Comment