What is the Best way to strip punctuation from a string in Python?

682    Asked by JoaquinaMesser in Python , Asked on Feb 22, 2021
Answered by Joaquina Messer

You can use the string.translate approach as it is very fast and easy to use.

s.translate(None, string.punctuation)

For higher versions of Python use the following code:

s.translate(str.maketrans('', '', string.punctuation))



Your Answer

Interviews

Parent Categories