xxxxxxxxxx
s = "aabbcadcba"
print(s.replace("a", "", 1) # removes only one "a" from the string.
out -> abbcadcba
print(s.replace("a", "") # removes all the "a"s from the string.
out -> bbcdcb
xxxxxxxxxx
a_string = "addbdcd"
a_string = a_string.replace("d", "")
print(a_string)
xxxxxxxxxx
varible.replace(letter, "") # blank quotes.
# e.g.
s = "Hello World"
print(s.replace('e', ""))
# Hllo World
# great for data cleansing
xxxxxxxxxx
# Simply use this function
def RemoveChars(string, what_to_remove): # what_to_remove should be a list containing the characters
s = "".join(c for c in string if c not in list("".join(what_to_remove)))
return s.strip()
my_string = "All.Good,Dogs.. Eat.! Shoes?"
things_to_remove = [',', '.', '!']
final = RemoveChars(my_string, things_to_remove)
print(final)
>>> 'AllGoodDogs Eat Shoes?'
xxxxxxxxxx
# Python program to remove single occurrences of a character from a string
text= 'ItsMyCoode'
print(text.replace('o','',1))