pythonアルゴリズム-1文字列-8スペース置換


pythonアルゴリズム-1文字列-8スペース置換
 
def replaceBlank(str, length):
    s = ''
    for i in range(length):
        if str[i] == ' ':
            str[i] = '%20'
        s += str[i]
    return s


if __name__ == '__main__':
    str = "Mr John Smith"
    str = list(str)
    a = replaceBlank(str, len(str))
    print(a)

オンライン実行:https://pyleetcode.gitee.io/codes_html/SYL_1%E5%AD%97%E7%AC%A6%E4%B8%B2_7%E7%A9%BA%E6%A0%BC%E6%9B%BF%E6%8D%A2.html