In Python3, string.punctuation
is a pre-initialized string used as string constant. In Python, string.punctuation
will give the all sets of punctuation.
Syntax : string.punctuation
Parameters : Doesn’t take any parameter, since it’s not a function.
Returns : Return all sets of punctuation.
Note : Make sure to import string library function inorder to use string.punctuation
Code #1 :
import string
result = string.punctuation
print (result)
|
Output :
!"#$%&'()*+, -./:;<=>?@[\]^_`{|}~
Code #2 : Given code tests for punctuation.
import string
Sentence = "Hey, Geeks !, How are you?"
for i in Sentence:
if i in string.punctuation:
print ( "Punctuation: " + i)
|
Output:
Punctuation:,
Punctuation: !
Punctuation:,
Punctuation: ?