punctuation python code example
Example 1: remove punctuation from string python
import re
s = "string. With. Punctuation?"
s = re.sub(r'[^\w\s]','',s)
s = "string. With. Punctuation?"
s.translate(str.maketrans('', '', string.punctuation))
Example 2: string punctuation python
Syntax : string.punctuation
Parameters : Doesn’t take any parameter, since it’s not a function.
Returns : Return all sets of punctuation.
CASE: 1
import string
result = string.punctuation
print(result)
CASE: 2
import string
sentence = "Hey, Geeks !, How are you?"
for i in sentence:
if i in string.punctuation:
print("Punctuation: " + i)