版权声明:转载请声名出处,谢谢 https://blog.csdn.net/u010591976/article/details/81974281
'''
@author dandanhuang
@email [email protected]
@python2.7.3
题目描述
请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
牛客网测试通过
'''
# -*- coding:utf-8 -*-
class Solution:
# s 源字符串
def replaceSpace(self, s):
#创建新的字符串
news = ''
for i in s:
if i == ' ':
news += '%20'
else:
news += i
return news
温故:用python只能创建新的字符串,如果需要在原来字符串上修改,用python怎么实现?
在python中字符串是不可以修改类型