Python学习第四天之数据的验证

柳三千

图片.png

#所有字符都是数字(阿拉伯数字)
print('123'.isdigit())#True
print('一二三'.isdigit())#False
print('0b1010'.isdigit())#False
print('ⅡⅢⅣ'.isdigit())#False
print('壹贰叁'.isdigit())#False
print('-'*50)
#--------------------------------------------------


#所有字符都是数字
print('123'.isnumeric())#True
print('一二三'.isnumeric())#True
print('ⅡⅢⅣ'.isnumeric())#True
print('壹贰叁'.isnumeric())#True
print('0b1010'.isnumeric())#False
print('-'*50)
#--------------------------------------------------


#所有字符都字母(包含中文字符)
print('hello你好'.isalpha())#True
print('hello你好123'.isalpha())#False
print('hello你好一二三'.isalpha())#True
print('hello你好ⅡⅢⅣ'.isalpha())#False
print('hello你好壹贰叁'.isalpha())#True
print('-'*50)
#--------------------------------------------------


#所有字符都是数字或字母(包含中文字符)
print('hello你好'.isalnum())#True
print('hello你好123'.isalnum())#True
print('hello你好一二三'.isalnum())#True
print('hello你好ⅡⅢⅣ'.isalnum())#True
print('hello你好壹贰叁'.isalnum())#True
print('-'*50)
#--------------------------------------------------


#所有字符的大写
print('HelloWorld'.isupper())#False
print('helloworld'.isupper())#False
print('HELLOWORLD'.isupper())#True
print('你好HELLOWORLD'.isupper())#True
print('-'*50)
#--------------------------------------------------

#所有字符的小写
print('HelloWorld'.islower())#False
print('helloworld'.islower())#True
print('HELLOWORLD'.islower())#False
print('你好hello'.islower())#True
print('-'*50)
#--------------------------------------------------


#所有字符都是首字母大写
print('Hello'.istitle())#True
print('HelloWorld'.istitle())#False  W不是首字母
print('Helloworld'.istitle())#True
print('Hello World'.istitle())#True
print('Hello world'.istitle())#False
print('-'*50)
#--------------------------------------------------

#所有字符都是空白字符
print('\t'.isspace())#True
print(' '.isspace())#True
print('\n'.isspace())#True
文章版权声明:除非注明,否则均为柳三千运维录原创文章,转载或复制请以超链接形式并注明出处。

目录[+]

取消
微信二维码
微信二维码
支付宝二维码