Python isnumeric()函数用法
Python字符串isnumeric()方法检查字符串是否仅包含数字字符。此方法仅用于unicode对象上。
注意 - 与Python 2不同,所有字符串在Python 3中都用Unicode表示。下面给出了一个示例。
isnumeric()函数语法
以下是isnumeric()方法的语法 -
str.isnumeric()
isnumeric()函数参数
NA
isnumeric()函数返回值
如果字符串中的所有字符都是数字,则此方法返回true,否则返回false。
isnumeric()函数用法示例
以下示例显示了isnumeric()方法的用法。
#!/usr/bin/python3str = "this2018" print(str.isnumeric()) str = "121323" print(str.isnumeric())
当运行上面的程序,它产生以下结果 -
FalseTrue