# -*- coding:utf-8 -*- # 请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy. # 则经过替换之后的字符串为We%20Are%20Happy。 # -*- coding:utf-8 -*- class Solution: # s 源字符串 def replaceSpace(self, s): # write code here if len(s)==0: return '' result = '' for item in s: if item.isspace():# str.isspace()的用法:检查字符串(字符)中是否只包含空格 result =result +'%20' else: result = result+item return result ################################################################################################# # -*- coding:utf-8 -*- class Solution: # s 源字符串 def replaceSpace(self, s): # write code here return s.replace(' ', '%20')
python-空格替换
最新推荐文章于 2024-04-30 19:24:04 发布