Python提供了isupper(),islower(),istitle()办法用来判别字符串的巨细写, 详细实例以下:
例如:(保举学习:Python视频教程)
>>> str_1 = "HELLO PYTHON" # 全年夜写 >>> str_2 = "Hello PYTHON" # 巨细写夹杂 >>> str_3 = "Hello Python" # 单词首字母年夜写 >>> str_4 = "hello python" # 全小写
isupper() 判别能否全是年夜写
>>> str_1.isupper() True >>> str_2.isupper() False >>> str_3.isupper() False >>> str_4.isupper() False
islower()判别能否全是小写
>>> str_1.islower() False >>> str_2.islower() False >>> str_3.islower() False >>> str_4.islower() True
istitle()判别首字母能否年夜写, 其他的能否小写
>>> str_1.istitle() False >>> str_2.istitle() False >>> str_3.istitle() True >>> str_4.istitle() False
更多Python相干技巧文章,请拜访Python教程栏目进行学习!
以上就是python用函数怎样判别巨细写的具体内容,更多请存眷资源魔其它相干文章!
标签: Python python教程 python编程 python使用问题
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!