Python
数字字符包括数字字符以及所有具有Unicode数值属性的字符。
isnumeric()
它返回True或False。
链接:https://www.learnfk.comhttps://www.learnfk.com/python3/python-string-isnumeric-method.html
来源:LearnFk无涯教程网
在这里,创建了一个简单的示例来检查字符串是否为数字。
# 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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Tony Bai · Go语言第一课 -〔Tony Bai〕
PPT设计进阶 · 从基础操作到高级创意 -〔李金宝(Bobbie)〕