2017-02-10 129 views
-4

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

例如: “12×24” 改为 “12×24”

+0

这个答案甚至是问题与我的相似吗?根本没有在我看来 – Weemo

回答

1

替换'x'使用str.replace()功能'<space>x<space>'为:

>>> my_str = '12x24' 
>>> my_str.replace('x', ' x ') 
'12 x 24' 
+0

优秀,那没有把戏。这么简单,但我无法想出它。谢谢。 – Weemo

1

使用replace方法来代替' x ''x'

string.replace('x', ' x ') 
相关问题