Answers for "get punctuation python"

5

remove punctuation from string python

#with re
import re
s = "string. With. Punctuation?"
s = re.sub(r'[^ws]','',s)
#without re
s = "string. With. Punctuation?"
s.translate(str.maketrans('', '', string.punctuation))
Posted by: Guest on May-26-2020
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
10

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

Python Answers by Framework

Browse Popular Code Answers by Language