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
相关推荐
寒山李白2 小时前
解决 python-docx 生成的 Word 文档打开时弹出“无法读取内容“警告
python·word·wps·文档·docx·qoder
2401_832365522 小时前
JavaScript中rest参数(...args)取代arguments的优势
jvm·数据库·python
Sirius.z3 小时前
第J3周:DenseNet121算法详解
python
2301_779622413 小时前
Go语言怎么用信号量控制并发_Go语言semaphore信号量教程【入门】
jvm·数据库·python
love530love3 小时前
精简版|Claude-HUD 插件介绍 + 一键安装教程
人工智能·windows·笔记
2301_766283443 小时前
c++如何将控制台输出保存到文件_cout重定向到txt【详解】
jvm·数据库·python
想成为优秀工程师的爸爸3 小时前
第三十篇技术笔记:郭大侠学UDS - 人有生老三千疾,望闻问切良方医
网络·笔记·网络协议·tcp/ip·信息与通信
小康小小涵4 小时前
基于ESP32S3实现无人机RID模块底层源码编译
linux·开发语言·python
lzjava20245 小时前
Python的函数
开发语言·python
tq10865 小时前
数学:约束表征空间的最小闭包
笔记