How to delete a character from a string using Python

前端 未结 16 1591
耶瑟儿~
耶瑟儿~ 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:32

    This is probably the best way:

    original = "EXAMPLE"
    removed = original.replace("M", "")
    

    Don't worry about shifting characters and such. Most Python code takes place on a much higher level of abstraction.

提交回复
热议问题