+ 7
Removing characters from strings
Does any one know how I can remove specific characters from a string in python? Example: word = str(input()) # Entered word is “Code” How can I remove a specific character like ‘e’ from the string?
7 Réponses
+ 2
Word = word.replace("a","b")
On first argument (a) written word/letter what do you want replace to other word/letter. On second argument (b) written word/letter for which do you want replace a first (a) argument. You can leave empty second argument, if you want delete any object from the string.
Example:
string = "hello world"
#I want to delete space in center of #hello/world
string = string.replace(" ","")
+ 4
Word = word.replace("e", "")
+ 4
Eliya Ben Baruch thanks alot 😁
+ 3
_nrkvv_ Thank you 😄
+ 2
Oh, Sinro on profile picture. Nice
+ 1
You are welcome