iNTERFACEWARE Products Manual > Learning Center > Learning Python > Working With Values and Variables > Variables > String and Number Conversion |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
When performing an assignment to a variable, you can convert a value from a string to a number, or vice versa. The following are examples of assignments in which a string is converted to an integer and to a floating point number:
Here, integertemp is assigned the number 37, and floattemp is assigned the number 98.6. The actual conversion is performed by two predefined chunks of code known as functions: int() converts a string to an integer, and float() converts a string to a floating point number.
The function str() converts a number to a string:
Functions are discussed in more detail in the Functions and Global Variables section. |