Skip to content Skip to sidebar Skip to footer

Does Python Have Built In String Validation For Special Characters And/or Punctuation?

Python has str.isalnum(), str.isdigit(), str.isupper(), str.islower(), str.isalpha(), but does it have any built-in string validation checking for special characters or punctuation

Solution 1:

The standard string module provides string.punctuation, which contains punctuation characters. You can test for membership in that:

defispunct(ch):
    return ch in string.punctuation

Solution 2:

Source: https://mail.python.org/pipermail/tutor/2001-October/009454.html

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

Post a Comment for "Does Python Have Built In String Validation For Special Characters And/or Punctuation?"