I need to add a space between X in a string. The program takes measurements in one field and I need to be able to separate integers from the "x" before doing the calculation.
For example: "12x24" should read "12 x 24"
I need to add a space between X in a string. The program takes measurements in one field and I need to be able to separate integers from the "x" before doing the calculation.
For example: "12x24" should read "12 x 24"
Replace 'x' with '<space>x<space>' using str.replace() function as:
>>> my_str = '12x24'
>>> my_str.replace('x', ' x ')
'12 x 24'
Use the replace method to substitute ' x ' for 'x':
string.replace('x', ' x ')