[英]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? Python具有str.isalnum()
, str.isdigit()
, str.isupper()
, str.islower()
, str.isalpha()
,但是它是否具有内置字符串验证功能来检查特殊字符或标点符号? (ie !@#$%^&*().,;'": ect) (即!@#$%^&*()。,;'“:ect)
The standard string
module provides string.punctuation
, which contains punctuation characters. 标准string
模块提供string.punctuation
,其中包含标点符号。 You can test for membership in that: 您可以通过以下方式测试成员资格:
def ispunct(ch):
return ch in string.punctuation
Source: https://mail.python.org/pipermail/tutor/2001-October/009454.html 来源: https : //mail.python.org/pipermail/tutor/2001-October/009454.html
import string
>>> print string.punctuation
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.