Python3 中的 isnumeric()函数

首页 / Python3入门教程 / Python3 中的 isnumeric()函数

Python isnumeric()方法检查字符串的所有字符是否都是数字字符。如果所有字符都为True,则返回True,否则返回False。

数字字符包括数字字符以及所有具有Unicode数值属性的字符。

isnumeric - 语法

isnumeric()

isnumeric - 返回

它返回True或False。

在这里,创建了一个简单的示例来检查字符串是否为数字。

# Python isnumeric() method example
# 变量声明
str = "12345"
# 函数调用
str2 = str.isnumeric()
# 显示结果
print(str2)

输出

True

让无涯教程在非数字字符串上对其进行测试,看看它是否返回False。

无涯教程网

# Python isnumeric() method example
# 变量声明
str = "javatpoint12345"
# 函数调用
str2 = str.isnumeric()
# 显示结果
print(str2)

输出

False

查看在python编程中如何以及如何应用isnumeric()方法的场景

# Python isnumeric() method example
str = "123452500" # True
if str.isnumeric() == True:
    print("Numeric")
else:
    print("Not numeric")
str2 = "123-4525-00" # False
if str2.isnumeric() == True:
    print("Numeric")
else:
    print("Not numeric")

输出

Numeric
Not numeric

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Python核心技术与实战 -〔景霄〕

性能测试实战30讲 -〔高楼〕

微信小程序全栈开发实战 -〔李艺〕

Linux内核技术实战课 -〔邵亚方〕

体验设计案例课 -〔炒炒〕

容量保障核心技术与实战 -〔吴骏龙〕

攻克视频技术 -〔李江〕

李智慧 · 高并发架构实战课 -〔李智慧〕

手把手带你写一个 MiniTomcat -〔郭屹〕

好记忆不如烂笔头。留下您的足迹吧 :)