每天一点python——day67

复制代码
#每天一点Python——67
#字符串判断方法:如图:
python 复制代码
#①判断指定字符串是否为合法标识符
s='hello,computer'
print(s.isidentifier())
#输出为False,不是合法标识符,这是因为标识符是由字母,数字,下划线组成,这里面有逗号
print('hello'.isidentifier())#输出为True,是合法的标识符
print('瓦工_'.isidentifier())
#为什么输出也为True呢?
#因为python3以上版本为了方便,标识符的字母不再局限于26个英文字母,也可以包含中文字符了
print('瓦工_123'.isidentifier())
#结果也是True
#②判断指定字符串是否全部都是由空白字符串组成【空白字符一般有回车,换行,水平制表符等】
print('\t'.isspace())
#\t为水平制表符,属于空白字符输出为True
#③判断指定字符串是否全部由字符串组成
print('abc'.isalpha())
#输出为True
print('瓦工'.isalpha())
#输出也为True
print('瓦工1'.isalpha())
#False。因为1不是字母
#④判断指定的字符串是否全部由十进制的数字组成
print('123'.isdecimal())
#为十进制
print('123四'.isdecimal())
#False
#去输入法里面找软键盘输入罗马数字123
print('ⅡⅢⅣ'.isdecimal())#判断是否为十进制
#结果也为False,所以罗马数字不是十进制数字
#⑤判断指定字符是否全部由数字组成
print('123'.isnumeric())
#True
print('123四'.isnumeric())
#发现也是True,所以四是数字
print('ⅡⅢⅣ'.isnumeric())
#True,罗马数字也是数字
#判断指定字符串是否全部由字母和数字组成
print('abc1'.isalnum())
#True
print('瓦工123'.isalnum())
#True
print('abc!'.isalnum())
#False,说明!不属于字母和数字
相关推荐
AI探索者13 小时前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者13 小时前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh15 小时前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅15 小时前
Python函数入门详解(定义+调用+参数)
python
曲幽16 小时前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama
两万五千个小时19 小时前
落地实现 Anthropic Multi-Agent Research System
人工智能·python·架构
哈里谢顿1 天前
Python 高并发服务限流终极方案:从原理到生产落地(2026 实战指南)
python
用户8356290780512 天前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng82 天前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi2 天前
Chapter 2 - Python中的变量和简单的数据类型
python