当前位置: 首页 > news >正文

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

相关文章:

  • 嵌入式培训机构四个月实训课程笔记(完整版)-Linux网络编程第一天-socket编程练习(物联技术666)
  • DCP文件传输的重要性与应用
  • GNU Tools使用笔记
  • 初识 Elasticsearch 应用知识,一文读懂 Elasticsearch 知识文集(1)
  • [足式机器人]Part2 Dr. CAN学习笔记-Advanced控制理论 Ch04-8 状态观测器设计 Linear Observer Design
  • K8S的存储卷---数据卷
  • 物流实时数仓DWD层——1.准备工作
  • 管理软件供应链中网络安全工具蔓延的三种方法
  • Nacos和Eureka比较、统一配置管理、Nacos热更新、多环境配置共享、Nacos集群搭建步骤
  • 14、强化学习Soft Actor-Critic算法:推导、理解与实战
  • Python Flask教程
  • MyBatisPlus
  • Vue中v-if与v-show区别详解
  • rke2 Online Deploy Rancher v2.8.0 latest (helm 在线部署 rancher v2.8.0)
  • 基于强化学习的航线规划算法
  • 《剑指offer》分解让复杂问题更简单
  • 【跃迁之路】【641天】程序员高效学习方法论探索系列(实验阶段398-2018.11.14)...
  • angular2开源库收集
  • const let
  • Js实现点击查看全文(类似今日头条、知乎日报效果)
  • markdown编辑器简评
  • MySQL常见的两种存储引擎:MyISAM与InnoDB的爱恨情仇
  • Twitter赢在开放,三年创造奇迹
  • 翻译:Hystrix - How To Use
  • 关于springcloud Gateway中的限流
  • 关于字符编码你应该知道的事情
  • 力扣(LeetCode)357
  • 前端学习笔记之观察者模式
  • 浅谈web中前端模板引擎的使用
  • 入口文件开始,分析Vue源码实现
  • 使用Maven插件构建SpringBoot项目,生成Docker镜像push到DockerHub上
  • 首页查询功能的一次实现过程
  • No resource identifier found for attribute,RxJava之zip操作符
  • 国内开源镜像站点
  • 曜石科技宣布获得千万级天使轮投资,全方面布局电竞产业链 ...
  • #define、const、typedef的差别
  • #中国IT界的第一本漂流日记 传递IT正能量# 【分享得“IT漂友”勋章】
  • (1/2) 为了理解 UWP 的启动流程,我从零开始创建了一个 UWP 程序
  • (9)YOLO-Pose:使用对象关键点相似性损失增强多人姿态估计的增强版YOLO
  • (env: Windows,mp,1.06.2308310; lib: 3.2.4) uniapp微信小程序
  • (附源码)springboot家庭财务分析系统 毕业设计641323
  • (附源码)springboot猪场管理系统 毕业设计 160901
  • (附源码)小程序 交通违法举报系统 毕业设计 242045
  • (力扣记录)235. 二叉搜索树的最近公共祖先
  • (强烈推荐)移动端音视频从零到上手(上)
  • (十一)JAVA springboot ssm b2b2c多用户商城系统源码:服务网关Zuul高级篇
  • (一)kafka实战——kafka源码编译启动
  • (总结)Linux下的暴力密码在线破解工具Hydra详解
  • ./configure、make、make install 命令
  • .gitignore文件使用
  • .NET 6 Mysql Canal (CDC 增量同步,捕获变更数据) 案例版
  • .NET CF命令行调试器MDbg入门(四) Attaching to Processes
  • .Net CF下精确的计时器
  • .net core 6 集成和使用 mongodb
  • .NET 的静态构造函数是否线程安全?答案是肯定的!