iNTERFACEWARE Products Manual > Learning Center > Learning Python > Functions and Global Variables > Local and Global Variables > Sample Code |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
The following sample code illustrates how Python determines whether a variable is a local variable or a global variable:
In this code, there are actually two copies of degc: a local variable, which is used inside FtoC(), and a global variable, which has 25.3 assigned to it. The local copy of degc is created by the degc = (degf - 32) / 1.8 statement, and goes away when the function is finished. The print statement prints the value of the global variable degc, which is 25.3. The other two rules for determining whether a variable inside a function is local or global are also illustrated by this example:
|