創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!
小編給大家分享一下用python判斷字符大小寫的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!
Python提供了isupper(),islower(),istitle()方法用來判斷字符串的大小寫。
1、isupper()方法
Python isupper() 方法檢測字符串中所有的字母是否都為大寫。
示例:
str = "THIS IS STRING EXAMPLE....WOW!!!"; print str.isupper(); str = "THIS is string example....wow!!!"; print str.isupper();
輸出如下:
True
False
2、islower()方法
Python islower() 方法檢測字符串是否由小寫字母組成。
islower()方法語法:str.islower()
示例:
str = "THIS is string example....wow!!!"; print str.islower(); str = "this is string example....wow!!!"; print str.islower();
輸出如下:
False
True
3、istitle()方法
Python istitle() 方法檢測字符串中所有的單詞拼寫首字母是否為大寫,且其他字母為小寫。
istitle()方法語法:str.istitle()
示例:
str = "This Is String Example...Wow!!!"; print str.istitle(); str = "This is string example....wow!!!"; print str.istitle();
輸出如下:
True
False
看完了這篇文章,相信你對用python判斷字符大小寫的方法有了一定的了解,想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝各位的閱讀!