Python isnumeric

Python isnumeric 函数用于检查字符是否为数字字符。如果它们是数字值,则此方法返回 True;否则返回 False。isnmeric 函数的语法为

String_Value.isnumeric()

Python isnumeric 示例

以下示例集可帮助您了解 isnumeric 函数。请参阅 字符串 及其 方法 文章,以了解 Python 中的内容。

Str1 = '123456789';
print('First Output  = ', Str1.isnumeric())

Str2 = '     ';
print('Output of a method For Empty Space is = ', Str2.isnumeric())

# Performing On Unicode Values
# \u00BD is the Unicode Value of '1/2'
Str3 = '\u00BD'.isnumeric()
print('Second Output  = ', Str3)

# Performing on both Numeric Values and Alphabets
Str4 = '123a'.isnumeric()
print('Third Output  = ', Str4)

# Performing on Float values
Str5 = '1234.67'.isnumeric()
print('Fourth Output  = ', Str5)

# Performing on Negative Values  
Str6 = '-1234'.isnumeric()
print('Fifth Output  = ', Str6)

# Performing on Numeric Values and Special Characters  
Str7 = '1234!@'.isnumeric()
print('Sixth Output  = ', Str7)
isnumeric Function Example