题解 | #替换空格#
替换空格
http://www.nowcoder.com/practice/0e26e5551f2b489b9f58bc83aa4b6c68
str.replace(old, new[, max])
Python replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次。
class Solution:
def replaceSpace(self , s ):
# write code here
string = s.replace(' ', '%20')
return string

查看5道真题和解析