Remove char at specific index - python

后端 未结 8 2032
清酒与你
清酒与你 2020-12-01 05:48

I have a string that has two \"0\" (str) in it and I want to remove only the \"0\" (str) at index 4

I have tried calling .replace but obviously that removes all \"0\

8条回答
  •  北海茫月
    2020-12-01 06:22

    def remove_char(input_string, index):
        first_part = input_string[:index]
        second_part - input_string[index+1:]
        return first_part + second_part
    
    s = 'aababc'
    index = 1
    remove_char(s,index)
    ababc
    

    zero-based indexing

提交回复
热议问题