is there way change global variable within function in python without passing in parameter?
test = 5 print(test) def changetest(): test = 10 return #no effect. test still equals 5 print(test)
you need specify want use global version of 'test' rather local one
test = 5 print(test) def changetest(): global test //added line test = 10 return changetest() print(test) //prints 10
Comments
Post a Comment