当前位置:  首页>> 技术小册>> Python合辑2-字符串常用方法

7、replace()

把字符串中的内容替换成指定的内容。

  1. s = 'string methods in python'.replace(' ', '-')
  2. print(s)
  3. # string-methods-in-python
  4. s = 'string methods in python'.replace(' ', '')
  5. print(s)
  6. # stringmethodsinpython