Replacing instances of a character in a string

前端 未结 13 2357
谎友^
谎友^ 2020-11-22 07:19

This simple code that simply tries to replace semicolons (at i-specified postions) by colons does not work:

for i in range(0,len(line)):
     if (line[i]==\"         


        
13条回答
  •  孤独总比滥情好
    2020-11-22 07:59

    How about this:

    sentence = 'After 1500 years of that thinking surpressed'
    
    sentence = sentence.lower()
    
    def removeLetter(text,char):
    
        result = ''
        for c in text:
            if c != char:
                result += c
        return text.replace(char,'*')
    text = removeLetter(sentence,'a')
    

提交回复
热议问题