新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python怎么判斷大小寫
python提供了isupper(),islower(),istitle()方法用來判斷字符串的大小寫,具體實例如下:

>>> 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
相關(guān)推薦:《Python入門教程》
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
當(dāng)前文章:創(chuàng)新互聯(lián)Python教程:python怎么判斷大小寫
本文鏈接:http://www.fisionsoft.com.cn/article/djihcje.html


咨詢
建站咨詢
