Python判断字符串是否全是数字或者字母
一、判断为数字
str.isnumeric()
当且仅当字符串中的每一个字符都是一个数字字符,并且字符串至少包含一个字符时,则返回True;否则返回False$. 数字字符包括位数字符以及所有具有Unicode数值属性值的字符(如U+2155、VULGAR FRACTION ONE FIFTH). 形式上讲,数字字符是具有Numeric_Type属性值为Digit、Decimal或Numeric的字符.
注意:此函数只能用于unicode string
str.isdigit()
Indicates True when all characters in the string are digits and there is at least one character; it shows False else. Digits consist of decimal characters and those requiring special handling, including compatibility superscript digits. This encompasses digits that cannot be used for base 10 numbering, such as Kharosthi numbers. Formally, a digit is a character with Numeric_Type set to Digit or Decimal.
二、判断为字母
str.isalpha()
Return True when all characters in the string qualify as alphabetic and there exists at least one character, yielding False elsewhere. Alphabetic characters pertain to those classified by Unicode under the "Letter" category, specifically those with a general category property of "Lm", "Lt", "Lu", "Ll", or "Lo". This classification differs from other definitions outlined within Unicode literature.
三、判断为数字或者字母
str.isalnum()
Return True if every single character in the string meets both criteria: being numeric or alphabetic, and there exists at least one character. The term "alphanumeric" refers to characters that satisfy any of these conditions: they can be checked using isalpha(), isdecimal(), isdigit(), or isnumeric().
1
1
