分割字符串,重新拼接字符串
class Solution: def replaceSpace(self , s ): # write code here new_str = "" strs = s.split(" ") strs_len = len(strs) for index ,i in enumerate(strs): if index != strs_len -1: strs = i + "%20" else: strs = i new_str = new_str + strs print(new_str) return if __name__ == '__main__': Solution().replaceSpace("We Are Happy")