python中isdigit()函数的用法,判断字符串中字符类型

isdigit()函数描述

isdigit()函数确切来说应该是python中字符串string类的一个类方法(函数),因为使用isdigit()时是通过“.”的形式进行引用,用来判断python字符串中的全部字符是否为0或正整数构成的数值类型,负数、浮点数中的负号和点“.”会被判断成一般字符。


isdigit()参数

无,字符串对象通过“.”进行引用。


isdigit()返回值类型

bool类型,True或者False;当字符串中的字符全是0或正整数时,返回True,否则返回False。


isdigit()实例代码

>>> '1'.isdigit()
True
>>> 'a'.isdigit()
False
>>> '000'.isdigit()
True
>>> '0.1'.isdigit()
False
>>> '-2'.isdigit()
False
>>> 'True'.isdigit()
False

全栈后端 / python教程 :


























Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.