Python数据的验证

数据的验证是指程序对用户输入的数据进行‘合法’性验证。

方法名

描述说明

str.isdigit()

所有字符都是数字(阿拉伯数字)

str.isumeric()

所有字符都是数字

str.isalpha()

所有字符都是字母(包含中文字符)

str.isalnum()

所有字符都是数字或字母(包含中文字符)

str.islower()

所有字符都是小写

str.isupper()

所有字符都是大写

str.istitle()

所有字符都是首字母大写

str.isspace()

所有字符都是空白字符(\n、\t等)

 

#isdigit()十进制的阿拉伯数字
print('123'.isdigit())#True
print('一二三'.isdigit())#False
print('0b1010'.isdigit())#False
print('Ⅲ'.isdigit())#False
print('*'*50)
#所有字符都是数字
print('123'.isnumeric())#True
print('一二三'.isnumeric())#True
print('0b1010'.isnumeric())#False
print('Ⅲ'.isnumeric())#True
print('壹'.isnumeric())#True
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'.islower())#False
print('helloworld'.islower())#True
print('hello你好'.islower())#True
print('*'*50)
print('HelloWorld'.isupper())#False
print('HELLOWORLD'.isupper())#True
print('HELLOWORLD你好'.isupper())#True
print('*'*50)
#判断首字母是否大写
print('Hello'.istitle())#True
print('HelloWorld'.istitle())#False
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

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌入式成长之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值