Python3 中的 isnumeric()函数

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

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

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

链接:https://www.learnfk.comhttps://www.learnfk.com/python3/python-string-isnumeric-method.html

来源:LearnFk无涯教程网

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

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

技术教程推荐

硅谷产品实战36讲 -〔曲晓音〕

Java核心技术面试精讲 -〔杨晓峰〕

零基础学Java -〔臧萌〕

Java性能调优实战 -〔刘超〕

Go 并发编程实战课 -〔晁岳攀(鸟窝)〕

分布式金融架构课 -〔任杰〕

跟着高手学复盘 -〔张鹏〕

如何讲好一堂课 -〔薛雨〕

大型Android系统重构实战 -〔黄俊彬〕

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