Computer Science, asked by attrice02, 11 months ago

How to write a program to remove letters in a particular word in Python?
Logic bata do koi. Please!

Answers

Answered by Anonymous
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,'')


attrice02: But, if we use the replace function, then won't there be an extra space which is not necessary?
attrice02: No no it's absolutely fine. :)
attrice02: Thank you for your help! <3
Answered by Anonymous
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:

nitish8089: @jahir well thanks if you don't say i will definitely continue amazing....
Similar questions