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
相关推荐
nimadan122 小时前
**AI漫剧软件2025推荐,解锁高性价比创意制作新体验**
人工智能·python
雾岛听蓝4 小时前
C++11新特性(lambda、包装器)
c++·经验分享·笔记
yunhuibin4 小时前
GoogLeNet学习
人工智能·python·深度学习·神经网络·学习
易辰君5 小时前
【Python爬虫实战】正则:中文匹配与贪婪非贪婪模式详解
开发语言·爬虫·python
秀儿还能再秀5 小时前
正则表达式核心语法 + Python的 re 库中常用方法
python·正则表达式
xcLeigh5 小时前
Python入门:Python3 正则表达式全面学习教程
python·学习·正则表达式·教程·python3
代码游侠6 小时前
Linux驱动复习——驱动
linux·运维·arm开发·笔记·学习
多恩Stone6 小时前
【C++ debug】在 VS Code 中无 Attach 调试 Python 调用的 C++ 扩展
开发语言·c++·python
枷锁—sha6 小时前
【CTFshow-pwn系列】03_栈溢出【pwn 053】详解:逐字节爆破!手写 Canary 的终极破解
网络·笔记·安全·网络安全
XW01059997 小时前
4-11判断素数
前端·python·算法·素数