I have just started to learn the programming basics. Python looked like a good starting point! I have run into a little snag that I can't seem to find an answer for that I could use some help with!
I understand that any values or variables created/defined within any given function are destroyed when the function has finished executing. However, what I am trying to do is to get the value of a function variable to be stored in a 'Global' variable outside of the function so that it can be used again later.
An example would be:
Expand|Select|Wrap|Line Numbers
- #This is my GLOBAL Variable to be used later
- FRUIT = "apple"
- def setFruit ():
- fruit = raw_input("What fruit do you want?")
- FRUIT = fruit #An attempt to store the value the user typed to the Global Variable
- def getFruit():
- print FRUIT
- setFruit()
- getFruit()
Any help would be appreciated! Thanks in advance!