美文网首页
python字符串isdigit、isnumeric、isdec

python字符串isdigit、isnumeric、isdec

作者: 十月里的男艺术家 | 来源:发表于2020-01-16 17:45 被阅读0次

isdigit()、isnumeric()、isdecimal()是python语言中字符串的内置类型。这三个函数主要区别是由于Unicode类型产生的。

decimal字符举例:

"12345"
"12"
"98201" 

digits字符举例:

"12345"
"1233⁴"
"⁴"

numerics字符举例:

"12345"
"½¼"
"½"
"12345½"

代码示例:

str1 = "362436"    #decimal characters
str2 = "3"         #unicode digit
str3 = "½¼"        #fractional value

print("str1 :", str1)
print("str1.isdecimal () : ", str1.isdecimal ())
print("str1.isnumeric () : ", str1.isnumeric ())
print("str1.isdigit () : ", str1.isdigit ())

print("str2 :", str2)
print("str2.isdecimal () : ", str2.isdecimal ())
print("str2.isnumeric () : ", str2.isnumeric ())
print("str2.isdigit () : ", str2.isdigit ())

print("str3 :", str3)
print("str3.isdecimal () : ", str3.isdecimal ())
print("str3.isnumeric () : ", str3.isnumeric ())
print("str3.isdigit () : ", str3.isdigit ())

运行结果:

str1 : 362436
str1.isdecimal () :  True
str1.isnumeric () :  True
str1.isdigit () :  True

str2 : 3
str2.isdecimal () :  True
str2.isnumeric () :  True
str2.isdigit () :  True

str3 : ½¼
str3.isdecimal () :  False
str3.isnumeric () :  True
str3.isdigit () :  False

相关文章

  • python字符串isdigit、isnumeric、isdec

    isdigit()、isnumeric()、isdecimal()是python语言中字符串的内置类型。这三个函数...

  • python中isdigit() isnumeric() isd

    转自:https://blog.csdn.net/Com_ma/article/details/77539833 ...

  • python学习-字符串(补充1)

    s.isdigit()、s.isnumeric()、s.isdecimal()的差别 转载自:百度知道 num =...

  • 判断密码强度

    Python字符串 str.isnumeric()检测字符串是否只由数字组成str.isalpha()检测字符串是...

  • 字符串

    1. isdigit() 检测字符串是否只由数字组成 描述isdigit() 方法检测字符串是否只由数字组成。语法...

  • 字符串的查询方法

    字符串的查询方法有:count(),find(),isdigit(),isalpha(),startswith()...

  • Isdigit and isalnum

    isdigit判断字符串是否全由数字组成 isalnum判断字符串是否全由数字和字母组成

  • 2018-09-19

    字符串的常用方法 S.isdigit() 判断字符串中是否全为数字 S.isalpha() 判断字...

  • 2019-04-09

    isdigit() : 检测字符串是否只由数字组成 1. print("网站名:{name}, 地址 {url}"...

  • PAT 1054

    1.isdigit函数原型:extern int isdigit(int c);用法:#include

网友评论

      本文标题:python字符串isdigit、isnumeric、isdec

      本文链接:https://www.haomeiwen.com/subject/wuxqzctx.html