iNTERFACEWARE Products Manual > Learning Center > Learning Python > Functions and Global Variables > Local and Global Variables > Local Variables |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
In Python, if you define a variable inside a function, it can only be used inside the function. Variables that are only defined inside a function are known as local variables. For example, take a look at the FtoC() function from the Return Values section:
This function defines a variable, named degc, that contains the converted Celsius temperature. This variable is only defined inside the FtoC() function; you cannot use it elsewhere. For instance, the following code is not legal:
If you run this program, Python flags the print statement as an error, stating that degc is not defined. |