How to delete a character from a string using Python

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

    How can I remove the middle character, i.e., M from it?

    You can't, because strings in Python are immutable.

    Do strings in Python end in any special character?

    No. They are similar to lists of characters; the length of the list defines the length of the string, and no character acts as a terminator.

    Which is a better way - shifting everything right to left starting from the middle character OR creation of a new string and not copying the middle character?

    You cannot modify the existing string, so you must create a new one containing everything except the middle character.

提交回复
热议问题