punctuation from string python code example

Example 1: python punctuation

import string 
print (string.punctuation)          # !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
sentence = "Hey guys !, How are 'you' ?"
for i in sentence:
    if i in string.punctuation:
        print(i)  	 				# ! , ' ' ?

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 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: ?