Answers for "string punctuation python"

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)  	 				# ! , ' ' ?
Posted by: Guest on May-21-2021
9

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: ?
Posted by: Guest on March-05-2021

Code answers related to "string punctuation python"

Python Answers by Framework

Browse Popular Code Answers by Language