How to delete a character from a string using Python

前端 未结 16 1590
耶瑟儿~
耶瑟儿~ 2020-11-22 16:35

There is a string, for example. EXAMPLE.

How can I remove the middle character, i.e., M from it? I don\'t need the code. I want to know:

16条回答
  •  生来不讨喜
    2020-11-22 17:25

    def kill_char(string, n): # n = position of which character you want to remove
        begin = string[:n]    # from beginning to n (n not included)
        end = string[n+1:]    # n+1 through end of string
        return begin + end
    print kill_char("EXAMPLE", 3)  # "M" removed
    

    I have seen this somewhere here.

提交回复
热议问题