If you want to delete a character at a certain index from the string, you can use string slicing to create a string without that character. In Python, strings are immutable, so you have to create a new string. You have a few options of how to create the new string. If you want to remove the ‘M’ wherever it appears:
1 | newstr = oldstr.replace("M", "") |
If you want to remove the central character:
1 2 | midlen = len(oldstr)/2 # //2 in python 3 newstr = oldstr[:midlen] + oldstr[midlen+1:] |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.