Python3 笔记:字符串的 isspace()、istitle()、isdecimal()

1、isspace() 方法检测字符串是否只由空白字符组成。

语法:str.isspace()

如果字符串中只包含空格,则返回 True,否则返回 False。

python 复制代码
str1 = '    '
str2 = 'hello '
print(str1.isspace())	# 运行结果:True
print(str2.isspace())	# 运行结果:False

2、istitle() 方法检测字符串中所有的单词拼写首字母是否为大写,且其他字母为小写。

语法:str.istitle()

如果字符串中所有的单词拼写首字母是否为大写,且其他字母为小写则返回 True,否则返回 False。

python 复制代码
str1 = 'A Title'
str2 = 'This is not a Title'
print(str1.istitle())	# 运行结果:True
print(str2.istitle())	# 运行结果:False

3、isdecimal() 方法检查字符串是否只包含十进制字符。

语法:str.isdecimal()

如果字符串中的所有字符都是十进制字符则返回True,否则返回False。

python 复制代码
str1 = '12345'
str2 = 'Number12345'
print(str1.isdecimal())	# 运行结果:True
print(str2.isdecimal())	# 运行结果:False
相关推荐
KaMeidebaby25 分钟前
卡梅德生物技术快报|纯化重组蛋白实操详解
人工智能·python·tcp/ip·算法·机器学习
Cloud_Shy61826 分钟前
解读《Effective Python 3rd Edition》:从练气到老魔(第五章 Item 30 - 32)
开发语言·人工智能·笔记·python·学习方法
天佑木枫1 小时前
15天Python入门系列 · 序
开发语言·python
happylifetree1 小时前
Python017-第二章15.数据容器-dict常用操作
python
问心无愧05131 小时前
ctf show web入门110
前端·笔记
装不满的克莱因瓶1 小时前
了解 LangChain 中的 LLM 与 ChatModel 的差异
人工智能·python·ai·langchain·llm·agent·chatmodel
道一231 小时前
Windows系统查看端口占用进程的3种实用方法
windows·笔记
IT知识分享2 小时前
从零开发在线简繁转换工具:OpenCC 实战、避坑经验与方案选型
javascript·python
lunzi_08262 小时前
【学习笔记】《Python编程 从入门到实践》第8章:函数定义、参数传递与模块导入
笔记·python·学习
杨运交2 小时前
[030][Web模块]Spring Boot 验证与 OpenAPI 集成实战:从校验规则到文档生成
前端·spring boot·python