An equivalent to string.ascii_letters for unicode strings in python 2.x?

后端 未结 4 1865
天命终不由人
天命终不由人 2020-12-16 00:30

In the \"string\" module of the standard library,

string.ascii_letters ## Same as string.ascii_lowercase + string.ascii_uppercase

is

4条回答
  •  臣服心动
    2020-12-16 00:56

    There's no string, but you can check whether a character is a letter using the unicodedata module, in particular its category() function.

    >>> unicodedata.category(u'a')
    'Ll'
    >>> unicodedata.category(u'A')
    'Lu'
    >>> unicodedata.category(u'5')
    'Nd'
    >>> unicodedata.category(u'ф') # Cyrillic f.
    'Ll'
    >>> unicodedata.category(u'٢') # Arabic-indic numeral for 2.
    'Nd'
    

    Ll means "letter, lowercase". Lu means "letter, uppercase". Nd means "numeric, digit".

提交回复
热议问题