1、使用字符串函数replace

>>> a = 'hello world'

>>> a.replace(' ', '')
'helloworld'

看上这种方法真的是很笨。

2、使用字符串函数split

>>> a = ''.join(a.split())

>>> print(a)
helloworld

3、使用正则表达式

>>> import re
>>> strinfo = re.compile()

>>> strinfo = re.compile(' ')

>>> b = strinfo.sub('', a)
>>> print(b)
helloworld

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2021-12-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
  • 2021-11-15
相关资源
相似解决方案