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
相关推荐
豆沙沙包?3 小时前
5.学习笔记-SpringMVC(P61-P70)
数据库·笔记·学习
白泽来了5 小时前
2个小时1.5w字| React & Golang 全栈微服务实战
笔记·go·react
fish_study_csdn5 小时前
pytest 技术总结
开发语言·python·pytest
咖啡调调。5 小时前
使用Django框架表单
后端·python·django
丶Darling.5 小时前
26考研 | 王道 | 数据结构笔记博客总结
数据结构·笔记·考研
BO_S__5 小时前
python调用ffmpeg对截取视频片段,可批量处理
python·ffmpeg·音视频
就叫飞六吧6 小时前
如何判断你的PyTorch是GPU版还是CPU版?
人工智能·pytorch·python
道长没有道观6 小时前
计算机操作系统笔记
笔记·考研·操作系统
pyengine7 小时前
基于pandoc的MarkDown格式与word相互转换小工具开发(pyqt5)
开发语言·python·qt·word
YuSun_WK7 小时前
配置MambaIRv2: Attentive State Space Restoration的环境
开发语言·python