How to write a program to remove letters in a particular word in Python?
Logic bata do koi. Please!
Answers
Answered by
1
Ans: python string immutability
I'm trying to remove specific characters from a string using Python. This is the code I'm using right now. Unfortunately it appears to do nothing to the string.
for char in line: if char in " ?.!/;:": line.replace(char,'')
I'm trying to remove specific characters from a string using Python. This is the code I'm using right now. Unfortunately it appears to do nothing to the string.
for char in line: if char in " ?.!/;:": line.replace(char,'')
attrice02:
But, if we use the replace function, then won't there be an extra space which is not necessary?
Answered by
6
Hi
replace() method of string is used to replace particular char from string.
with the help of replace() method I am going to replace all "a" with "v"
>>> oldName = "Ajay Rawat";
>>> newName = oldName.replace("a", "v");
>>> print(newName)
outpur: Ajvy Rvwvt
Another example:
To replace first char of every item from list:
fruites = ['Avocado','Orange', 'Bananas', 'Jackfruit']
for i, s in enumerate(fruites):
fruites[i] = s.replace("a", "A")
print(fruites)
Attachments:


Similar questions