Aug-22-2018, 04:47 PM
Hello,
I am a beginner in python.
I am trying to use a global variable in local namespace i.e. within a function.The program is following:
Why it is taking my_var's value 10 here?
I am a beginner in python.
I am trying to use a global variable in local namespace i.e. within a function.The program is following:
def my_func(): global my_var print my_var my_var=10 my_var=20 my_func() print my_var * 5
Output:20
50
The second output is creating little confusion.i think this should simply multiply my_var's value 20 with 5.Why it is taking my_var's value 10 here?