请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
# -*- coding:utf-8 -*-
class Solution:
# s 源字符串
def replaceSpace(self, s):
s1 = s.replace(" ","%20")
return s1
# write code here
python字符串的内建函数
http://www.runoob.com/python3/python3-string.html
python的字符串是不可变类型,可对原字符串进行 切片 ,转化为list后join(),重新赋值 ,使用字符串的replace()进行“改变” (新的字符)