Python数据的验证

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

|----------------|----------------------|
| 方法名 | 描述说明 |
| str.isdigit() | 所有字符都是数字(阿拉伯数字) |
| str.isumeric() | 所有字符都是数字 |
| str.isalpha() | 所有字符都是字母(包含中文字符) |
| str.isalnum() | 所有字符都是数字或字母(包含中文字符) |
| str.islower() | 所有字符都是小写 |
| str.isupper() | 所有字符都是大写 |
| str.istitle() | 所有字符都是首字母大写 |
| str.isspace() | 所有字符都是空白字符(\n、\t等) |

python 复制代码
#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
相关推荐
量化吞吐机4 分钟前
2026年AI量化工具评估,先分开学习开发和验证
人工智能·python
库克克9 分钟前
【C++】类和对象--this指针详解
java·开发语言·c++
JackieZhengChina24 分钟前
image-viewer-js 开源图片查看插件完整教程
开发语言·javascript·开源
光影少年37 分钟前
react的View/Text/Image/ScrollView 常用组件注意事项
开发语言·前端·javascript·react.js·前端框架
白帽小阳1 小时前
Typora插件开发指南:打造专属IDE式写作环境
c语言·网络·python·网络安全·github·pygame·护网行动
满怀冰雪1 小时前
02-安装 PaddlePaddle:CPU、GPU 与环境检查入门
人工智能·python·paddlepaddle
hanxiuchao1 小时前
告别客户端臃肿!网页端 M3U8 播放调试方案,适配全办公场景
运维·python·django·m3u8·m3u8播放
3DVisionary1 小时前
如何用单目高速DIC把“看不见“的振动变成“数得清“的数据
java·spring boot·python·数码相机·微小振动·精密件·单目高速dic
FriendshipT1 小时前
Ultralytics:解读BNContrastiveHead模块
人工智能·pytorch·python·深度学习·目标检测
tkevinjd1 小时前
416分割等和子集
java·python·算法·leetcode·职场和发展