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: ?
Recommended Posts:
- Python | Merge Python key values to list
- Python | Index of Non-Zero elements in Python list
- Python | Convert list to Python array
- Important differences between Python 2.x and Python 3.x with examples
- Reading Python File-Like Objects from C | Python
- Python | Add Logging to Python Libraries
- Python | Add Logging to a Python Script
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Visualizing O(n) using Python
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- Python vs PHP
- zip() in Python
- try and except in Python
- SQL using Python | Set 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : shubham_singh



