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
相关推荐
Ven%1 分钟前
在魔搭 Notebook 容器里跑 Qwen Code:从零配置到省魔粒的完整实践
人工智能·python·ai·ai编程·modelscope
2401_885885046 分钟前
巴林语音通知接口如何对接?系统告警语音API接入教程
android·前端·网络·python·语音识别
H.莓飛16 分钟前
【数据结构】排序总结与规模实测
linux·服务器·开发语言·数据结构·visual studio·1024程序员节
执假以为真29 分钟前
Python内存分析器memray的简单介绍
python
会编程的吕洞宾32 分钟前
RAG检索质量怎么评估?3个指标+LLM裁判实战
java·开发语言·人工智能·后端
FLJwu38 分钟前
运动相机采购实战|第四篇(终章):一张清单走完选型全流程,把风险拦在源头
c语言·开发语言·数码相机·运动相机·oem 量产
收纳过往38 分钟前
数据库加索引的时机:慢查询日志说话
android·开发语言·数据库·python·低代码·rxjava
小鹿学程序1 小时前
市赛python学习
python
高洁011 小时前
知识图谱:结构化表达实体与关系的知识组织技术
人工智能·python·深度学习·机器学习·迁移学习
骊山道童1 小时前
第 1 周 LLM 原理与高效微调知识精讲手册
python