Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 16 Online
OpenStudy (anonymous):

can I call a global variable inside a function? Eg to update a global list of answers to the number of times a function iterates

OpenStudy (anonymous):

Yes. If your variable is created outside the function, then inside the function type global name_of_variable like in this paste http://pastebin.com/JA6FJeAb

OpenStudy (anonymous):

ah so the "global" command is used to call a global variable inside a function

OpenStudy (anonymous):

It tells the interpreter that it should not create the variable in the local scope of that function. Rather, look outside the function, in the global scope, for the variable with this name.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!