xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to convert string data to integer or float types in Python
Python Online Editor
Execute Code
More Python Sample Codes
# Convert string to integer string_variable = "1225" try: output_integer = int(string_variable) print(output_integer + 25) # 25 added to the integer. Output will be 1250 except ValueError: print(f"{string_variable} cannot be converted to an integer.") # Convert string to float string_new_variable = "1225.25" try: output_float = float(string_new_variable) print(output_float + 12.46) # 12.46 added to the float. Output will be 1237.71 except ValueError: print(f"{string_new_variable} cannot be converted to a decimal.") # Another example string_variable2 = "T1225" try: output_integer2 = int(string_variable2) print(output_integer2 + 25) except ValueError: print(f"{string_variable2} cannot be converted to an integer.")