How to delete all instances of a character in a string in python?

前端 未结 6 1901
清酒与你
清酒与你 2020-12-08 00:04

How do I delete all the instances of a character in this string? Here is my code:

def findreplace(char, string):
    place = string.index(char)
    string[pl         


        
6条回答
  •  猫巷女王i
    2020-12-08 00:40

    # s1 == source string
    # char == find this character
    # repl == replace with this character
    def findreplace(s1, char, repl):
        s1 = s1.replace(char, repl)
        return s1
    
    # find each 'i' in the string and replace with a 'u'
    print findreplace('it is icy', 'i', 'u')
    # output
    ''' ut us ucy '''
    

提交回复
热议问题