1import string
2print (string.punctuation) # !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
3sentence = "Hey guys !, How are 'you' ?"
4for i in sentence:
5 if i in string.punctuation:
6 print(i) # ! , ' ' ?
1Syntax : string.punctuation
2Parameters : Doesn’t take any parameter, since it’s not a function.
3Returns : Return all sets of punctuation.
4CASE: 1
5# import string library function
6import string
7# Storing the sets of punctuation in variable result
8result = string.punctuation
9# Printing the punctuation values
10print(result)
11#OUTPUT : !"#$%&'()*+, -./:;<=>?@[\]^_`{|}~
12
13CASE: 2
14# import string library function
15import string
16
17# An input string.
18sentence = "Hey, Geeks !, How are you?"
19for i in sentence:
20 # checking whether the char is punctuation.
21 if i in string.punctuation:
22 # Printing the punctuation values
23 print("Punctuation: " + i)
24
25# Output:
26
27# Punctuation:,
28# Punctuation: !
29# Punctuation:,
30# Punctuation: ?
31