python punctuations strings code example
Example: 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 library function
import string
# Storing the sets of punctuation in variable result
result = string.punctuation
# Printing the punctuation values
print(result)
#OUTPUT : !"#$%&'()*+, -./:;<=>?@[\]^_`{|}~
CASE: 2
# import string library function
import string
# An input string.
sentence = "Hey, Geeks !, How are you?"
for i in sentence:
# checking whether the char is punctuation.
if i in string.punctuation:
# Printing the punctuation values
print("Punctuation: " + i)
# Output:
# Punctuation:,
# Punctuation: !
# Punctuation:,
# Punctuation: ?