python中常用检测字符串相关函数汇总,python字符串
python中常用检测字符串相关函数汇总,python字符串
本文实例汇总了python中常用检测字符串相关函数。分享给大家供大家参考。具体分析如下:
下面的python代码可用于检测字符串,包括是否全部为数字,是否包含数字,是否包含标题单词,是否包含大写字母,是否包含小写字母,是否包含空格,是否以指定的字符开头和结尾。
my_string = "Hello World" my_string.isalnum() #检测所有字符是否都是数字 my_string.isalpha() #检测字符串中的所有字符是否都是字母 my_string.isdigit() #检测字符串是否包含数字 my_string.istitle() #检测字符串是否包含标题单词 my_string.isupper() #检测字符串是否包含大写字母 my_string.islower() #检测字符串是否包含小写字母 my_string.isspace() #检测字符串是否包含空格 my_string.endswith('d') #检测字符串是否以字符d结束 my_string.startswith('H') #检测字符串是否以大写字母H开头
下面显示返回结果
my_string="Hello World" print my_string.isalnum() #False print my_string.isalpha() #False print my_string.isdigit() #False print my_string.istitle() #True print my_string.isupper() #False print my_string.islower() #False print my_string.isspace() #False print my_string.endswith('d') #True print my_string.startswith('H') #True
希望本文所述对大家Python程序设计有所帮助。
相关内容
- python获取本机外网ip的方法,pythonip
- 详解Python中with语句的用法,详解pythonwith语句
- Python代码调试的几种方法总结,python代码几种方法
- Python下的twisted框架入门指引,pythontwisted
- Python下的subprocess模块的入门指引,pythonsubprocess
- 用Python实现换行符转换的脚本的教程,python换行符教程
- 从Python的源码浅要剖析Python的内存管理,python内存管理
- 使用Python的Twisted框架编写简单的网络客户端,pythontw
- 使用Python的Twisted框架实现一个简单的服务器,pythontw
- 利用Python的Twisted框架实现webshell密码扫描器的教程,
评论关闭