I am trying to define a function which will take one parameter, a string which represents a word, and removes characters considered punctuation from everywhere in the word. I am trying to use the .replace() function only.
For example: if the word is " inc#credi!ble" it will return "incredible". However, the one I am writing now is replacing only one parameter. Below is the code:
punctuation_chars = ["'", '"', ",", ".", "!", ":", ";", '#', '@']
def strip_punctuation(word):
for char in word:
if char in punctuation_chars:
char_without_punct = word.replace(char,"",)
return char_without_punct
y = strip_punctuation("#incr!edible") print(y)