iNTERFACEWARE Products Manual > Learning Center > Learning Python > Functions and Global Variables > Return Values |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
To return a value from a function, use the return statement. Here is an example:
The FtoC() function converts temperature values from Fahrenheit to Celsius. The return statement specifies that the converted temperature, stored in degc, is the return value of the function. This return value can be treated like any other value: in particular, it can be assigned to a variable. In the example above, the return value from FtoC() is assigned to the variable temperature.
A function can return more than one value. For instance:
This function is passed a temperature in Fahrenheit and converts it to both Celsius and Kelvin. The function returns two values: the Celsius temperature, and the Kelvin temperature. These are assigned to the variables ctemp and ktemp.
|