my_string = 'voltage is E=200V and the current is I=4.5A' # Assuming you are working with the hard coded index voltage = float(my_string[13:16]) current = float(my_string[39:42]) print(voltage, current)