Python - local and global scope in functions -
this question has answer here:
i have written simple function understand local , global scope in python .
x = 50 def func(x): print('x is', x) x = 2 print('changed local x to', x) func(x) print('x still', x) what want understand here inside function during x= 2 assignment whether new variable getting created globally variable x still holding value 50 . how process occurs in python?
yes, new variable created. python's scoping rules mean variables of same name in different scopes unrelated - variable references innermost scope containing variable name unless overridden global statement.
Comments
Post a Comment