Python string | printable()
In Python3, string.printable is a pre-initialized string used as string constant. In Python, string.printable will give the all sets of punctuation, digits, ascii_letters and whitespace.
Syntax : string.printable
Parameters : Doesn’t take any parameter, since it’s not a function.
Returns : Return all sets of punctuation, digits, ascii_letters and whitespace.
Note : Make sure to import string library function inorder to use string.printable
Code #1 :
# import string library function import string # Storing the sets of punctuation, # digits, ascii_letters and whitespace # in variable result result = string.printable # Printing the set of values print(result) |
Output :
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+, -./:;<=>?@[\]^_`{|}~
Code #2 : Given code tests for the printable values.
# import string library function import string # An input string. Sentence = "Hey, Geeks !, How are you?" for i in Sentence: # checking whether the char is printable value if i in string.printable: # Printing the printable values print("printable Value is: " + i) |
Output:
printable Value is: H printable Value is: e printable Value is: y printable Value is:, printable Value is: printable Value is: G printable Value is: e printable Value is: e printable Value is: k printable Value is: s printable Value is: ! printable Value is:, printable Value is: printable Value is: H printable Value is: o printable Value is: w printable Value is: printable Value is: a printable Value is: r printable Value is: e printable Value is: printable Value is: y printable Value is: o printable Value is: u printable Value is: ?
Recommended Posts:
- String slicing in Python to check if a string can become empty by recursive deletion
- Python | Check if given string can be formed by concatenating string elements of list
- Python | Check if string ends with any string in given list
- Python | Sorting string using order defined by another string
- String slicing in Python to rotate a string
- Python | Check if a given string is binary string or not
- Python String | max()
- Python String
- Python String | min()
- Python | Add one string to another
- string capitalize() in Python
- Python String | find()
- Python string | swapcase()
- Python | String startswith()
- String rindex() in python
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




