Sunday, October 5, 2025
HomeLanguagesstring.punctuation in Python

string.punctuation in Python

In Python3, string.punctuation is a pre-initialized string used as string constant. In Python, string.punctuation will give the all sets of punctuation.

Syntax : string.punctuation

Parameters : Doesn’t take any parameter, since it’s not a function.

Returns : Return all sets of punctuation.

Note : Make sure to import string library function inorder to use string.punctuation

Code #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 :

!"#$%&'()*+, -./:;<=>?@[\]^_`{|}~

 
Code #2 : Given code tests for punctuation.




# 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: ?
RELATED ARTICLES

Most Popular

Dominic
32337 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6706 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11934 POSTS0 COMMENTS
Shaida Kate Naidoo
6821 POSTS0 COMMENTS
Ted Musemwa
7087 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6778 POSTS0 COMMENTS