Python中判断字符串内容的函数
2018-11-08 16:11
99 查看
isdigit() : 判断字符串是否全部是数字
isalpha() : 判断字符串是否同时含有字母和数字
isalnum() : 判断是否只含有字母,不区分大小写
[code]str_1 = "123" str_2 = "Abc" str_3 = "123Abc" #用str.isdigit函数判断是否数字 print(str_1.isdigit()) Ture print(str_2.isdigit()) False print(str_3.isdigit()) False #用str.isalpha判断是否字母 print(str_1.isalpha()) False print(str_2.isalpha()) Ture print(str_3.isalpha()) False #str.isalnum判断是否数字和字母的组合 print(str_1.isalnum()) Ture print(str_2.isalnum()) Ture print(str_1.isalnum()) Ture #注意:如果字符串中含有除了字母或者数字之外的字符,比如空格,也会返回False阅读更多
相关文章推荐
- Python startswith() 函数 判断字符串开头
- Python中用startswith()函数判断字符串开头的教程
- python 判断字符串的内容是不是数字
- Python函数操作集锦之字符串测试、判断函数
- python 用函数strptime判断字符串是否为日期格式
- Python中用startswith()函数判断字符串开头
- # python中字符串的大小写转换和判断字符串大小写的函数小结
- python---函数(返回整型最大/最小值、返回字符串最长的串、函数返回任意的module的帮助文档内容、读取目录下内容、)
- python:如何判断字符串中的内容是否都为数字
- python3 关于字符串的内容(split join strip replace lower upper caitalize 函数用法)
- Python endswith() 函数 判断字符串结尾
- Python实现判断字符串中包含某个字符的判断函数示例
- python判断字符串中包含某个字符的判断函数脚本
- java python oracle判断字符串是否为数字的函数
- python 字符串判断函数
- Python中常用的字符串内建函数
- python判断输入的字符串是否为数字
- python 判断字符串
- Python函数——查找字符串第n次出现的位置
- python 函数的文档字符串 docstrings