剑指offer面试题【5】--替换空格【Python】【字符串】

题目描述

请实现一个函数,将一个字符串中的每个空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。

Python实现

# -*- coding:utf-8 -*-
class Solution:
    # s 源字符串
    def replaceSpace(self, s):
        # write code here
        list=s.split(" ")
        return "%20".join(list)

猜你喜欢

转载自blog.csdn.net/weixin_42702666/article/details/88575521