如何在字符串中的特定字符后添加空格?

Wee*_*emo -1 python string join

我需要在字符串中的 X 之间添加一个空格。该程序在一个字段中进行测量,在进行计算之前,我需要能够将整数与“x”分开。

例如:“12x24”应为“12 x 24”

Moi*_*dri 7

替换'x''<space>x<space>'usingstr.replace()函数:

>>> my_str = '12x24'
>>> my_str.replace('x', ' x ')
'12 x 24'
Run Code Online (Sandbox Code Playgroud)