【发布时间】:2014-02-23 09:39:39
【问题描述】:
如何在 python 中删除字符串中的特定空格。
我的输入字符串是:,
str1 = """vendor_id\t: GenuineIntel
cpu family\t: 6
model\t\t: 58
model name\t: Intel(R) Core(TM) i3-3120M CPU @ 2.50GHz
stepping\t: 9
cpu MHz\t\t: 2485.659
cache size\t: 6144 KB
fpu\t\t: yes
fpu_exception\t: yes
cpuid level\t: 5
wp\t\t: yes"""
我需要的输出是:
>>>print str1
vendor_id: GenuineIntel
cpu family: 6
model: 58
model name: Intel(R) Core(TM) i3-3120M CPU @ 2.50GHz
stepping: 9
cpu MHz: 2485.659
cache size: 6144 KB
fpu: yes
fpu_exception: yes
cpuid level: 5
wp: yes
【问题讨论】:
-
你确定你的输出字符串没有空格吗?
-
我已将您的示例编辑为 a) 是有效的 Python,并且 b) 用
\t字符替换其中的现有选项卡,因为这在这里很重要但不可见。如果可以的话,请务必使用print repr(str1)向我们展示其中真正的内容。
标签: python string python-2.7