How to remove character from string in python | Remove char from string.

To work with strings, you must be familiar with the string its method, and how it works, also you need a sound knowledge of the list as well, but in case if you don’t know, then you just need to know the basics of programming and you are good to go.

First and foremost, let us see the actual algorithm that is how will approach the problem. And this way of approaching problems is quite essential, simply put you divide the problems into smaller chunks and then you conquer it.

Algorithm:

  1. We will take a string
  2. We will ask the user to input his/her desired character
  3. Take new empty string
  4. Iterate through old_string
  5. If char is in old_string
  • Do not include it in new_string
  • Else include it in new_string
  1. print the new_string 

How to remove character from string in python

 

output

Code:

  1. We have taken a string
  2. We have taken a variable called char to take input from the user
  3. We have taken a new_string for storing the output
  4. We have iterated through the string and each character of string comes in I in each iteration
  5. We have checked if I value is equal to input char from the user
  6. If it is equal then we have inserted an empty space into new_string.
  7. If it is not equal then we have inserted the char as it is in new_string.
  8. Finally, we have printed the output

Waqar Khan

Hello, everyone, I am Waqar Khan. I have done my B.tech in Computer Science. I love to write about Computer Informational blogs. Before write I did proper research on it. Hope you like our blogs. Thank you.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *