小册名称:Python合辑2-字符串常用方法
7、replace()
把字符串中的内容替换成指定的内容。
s = 'string methods in python'.replace(' ', '-')print(s)# string-methods-in-pythons = 'string methods in python'.replace(' ', '')print(s)# stringmethodsinpython
s = 'string methods in python'.replace(' ', '-')
print(s)
# string-methods-in-python
s = 'string methods in python'.replace(' ', '')
# stringmethodsinpython