msa*_*aio 60 python string strip
如何从Python字符串中删除逗号Foo, bar?我试过了'Foo, bar'.strip(','),但没办法.
eum*_*iro 127
s = s.replace(',', '')
Run Code Online (Sandbox Code Playgroud)
pra*_*nsg 13
使用replace字符串的方法不是strip:
s = s.replace(',','')
Run Code Online (Sandbox Code Playgroud)
一个例子:
>>> s = 'Foo, bar'
>>> s.replace(',',' ')
'Foo bar'
>>> s.replace(',','')
'Foo bar'
>>> s.strip(',') # clears the ','s at the start and end of the string which there are none
'Foo, bar'
>>> s.strip(',') == s
True
Run Code Online (Sandbox Code Playgroud)