[Tutor] "Forward" declarations

alan.gauld@bt.com alan.gauld@bt.com
Fri, 18 Aug 2000 18:01:02 +0100

> How do I use a variable that is only declared later on in the file? Is
> global what I'm looking for? 

Nope. Global brings a variable name from outside your function 
into your function(rather than creating a local)

You can't use a variable before its created. You create one by assigning.

foo = spam + 1	# error spam doesn't exist yet.
foo = 5 + 7		# you just created foo with value 12
spam = foo		# OK you created spam and gave it the same value as

For more info on use of names and 'global' in Python try 
the namespaces chapter in my tutor or the official tutor:

Alan G.