python字符串轉(zhuǎn)換大小寫的方法

小編給大家分享一下python字符串轉(zhuǎn)換大小寫的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

創(chuàng)新互聯(lián)公司專注于企業(yè)全網(wǎng)整合營(yíng)銷推廣、網(wǎng)站重做改版、都勻網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5高端網(wǎng)站建設(shè)商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為都勻等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

平常開發(fā)過(guò)程中對(duì)字符串的一些操作:

#字母大小寫轉(zhuǎn)換
#首字母轉(zhuǎn)大寫
#去除字符串中特殊字符(如:'_','.',',',';'),然后再把去除后的字符串連接起來(lái)
#去除'hello_for_our_world'中的'_',并且把從第一個(gè)'_'以后的單詞首字母大寫

代碼實(shí)例:

#字母大小寫轉(zhuǎn)換
#首字母轉(zhuǎn)大寫
#去除字符串中特殊字符(如:'_','.',',',';'),然后再把去除后的字符串連接起來(lái)
#去除'hello_for_our_world'中的'_',并且把從第一個(gè)'_'以后的單詞首字母大寫
low_strs= 'abcd'
uper_strs= 'DEFG'
test_strA= 'hello_world'
test_strB= 'goodBoy'
test_strC= 'hello_for_our_world'
test_strD= 'hello__our_world_'
  
#小寫轉(zhuǎn)大寫
low_strs= low_strs.upper()
print('abcd小寫轉(zhuǎn)大寫:', low_strs)
  
#大寫轉(zhuǎn)小寫
uper_strs= uper_strs.lower()
print('DEFG大寫轉(zhuǎn)小寫:', uper_strs)
  
#只大寫第一個(gè)字母
test_strB= test_strB[0].upper()+ test_strB[1:]
print('goodBoy只大寫第一個(gè)字母:', test_strB)
  
#去掉中間的'_',其他符號(hào)都是可以的,如:'.',',',';'
test_strA= ''.join(test_strA.split('_'))
print('hello_world去掉中間的\'_\':', test_strA)
  
#去除'hello_for_our_world'中的'_',并且把從第一個(gè)'_'以后的單詞首字母大寫
def get_str(oriStr,splitStr):
    str_list= oriStr.split(splitStr)
    if len(str_list) >1:
        for indexin range(1,len(str_list)):
            if str_list[index] != '':
                str_list[index]= str_list[index][0].upper()+ str_list[index][1:]
            else:
                continue
        return ''.join(str_list)
    else:
        return oriStr
  
print('去除\'hello_for_our_world\'中的\'_\',并且把從第一個(gè)\'_\'以后的單詞首字母大寫:', get_str(test_strC,'_'))
print('去除\'hello__our_world_\'中的\'_\',并且把從第一個(gè)\'_\'以后的單詞首字母大寫:', get_str(test_strD,'_'))

看完了這篇文章,相信你對(duì)python字符串轉(zhuǎn)換大小寫的方法有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

當(dāng)前題目:python字符串轉(zhuǎn)換大小寫的方法
文章源于:http://muchs.cn/article30/jcpjso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁(yè)設(shè)計(jì)公司、微信小程序、App設(shè)計(jì)、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司