0


Python判断字符串是否全是数字或者字母

一、判断为数字

str.isnumeric()

Return

True

if all characters in the string are numeric characters, and there is at least one character,

False

otherwise. Numeric characters include digit characters, and all characters that have the Unicode numeric value property, e.g. U+2155, VULGAR FRACTION ONE FIFTH. Formally, numeric characters are those with the property value Numeric_Type=Digit, Numeric_Type=Decimal or Numeric_Type=Numeric.

注意:此函数只能用于unicode string

str.isdigit()

Return

True

if all characters in the string are digits and there is at least one character,

False

otherwise. Digits include decimal characters and digits that need special handling, such as the compatibility superscript digits. This covers digits which cannot be used to form numbers in base 10, like the Kharosthi numbers. Formally, a digit is a character that has the property value Numeric_Type=Digit or Numeric_Type=Decimal.

二、判断为字母

str.isalpha()

Return

True

if all characters in the string are alphabetic and there is at least one character,

False

otherwise. Alphabetic characters are those characters defined in the Unicode character database as “Letter”, i.e., those with general category property being one of “Lm”, “Lt”, “Lu”, “Ll”, or “Lo”. Note that this is different from the “Alphabetic” property defined in the Unicode Standard.

三、判断为数字或者字母

str.isalnum()

Return

True

if all characters in the string are alphanumeric and there is at least one character,

False

otherwise. A character

c

is alphanumeric if one of the following returns

True

:

c.isalpha()

,

c.isdecimal()

,

c.isdigit()

, or

c.isnumeric()

.

【1】Built-in Types — Python 3.10.0 documentation


本文转载自: https://blog.csdn.net/liveshow021_jxb/article/details/121442798
版权归原作者 liveshow021_jxb 所有, 如有侵权,请联系我们删除。

“Python判断字符串是否全是数字或者字母”的评论:

还没有评论