中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

python代碼實(shí)例大小寫(xiě)轉(zhuǎn)換,首字母大寫(xiě),去除特殊字符

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用

總結(jié)我們?cè)谄匠i_(kāi)發(fā)過(guò)程中對(duì)字符串的一些操作:

#字母大小寫(xiě)轉(zhuǎn)換

#首字母轉(zhuǎn)大寫(xiě)

#去除字符串中特殊字符(如:'_','.',',',';'),然后再把去除后的字符串連接起來(lái)

#去除'hello_for_our_world'中的'_',并且把從第一個(gè)'_'以后的單詞首字母大寫(xiě)

代碼實(shí)例:

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

運(yùn)行效果:

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32

Type "copyright", "credits" or "license()" for more information.

>>> ================================ RESTART ================================

>>>

abcd小寫(xiě)轉(zhuǎn)大寫(xiě): ABCD

DEFG大寫(xiě)轉(zhuǎn)小寫(xiě): defg

goodBoy只大寫(xiě)第一個(gè)字母: GoodBoy

hello_world去掉中間的'_': helloworld

去除'hello_for_our_world'中的'_',并且把從第一個(gè)'_'以后的單詞首字母大寫(xiě): helloForOurWorld

去除'hello__our_world_'中的'_',并且把從第一個(gè)'_'以后的單詞首字母大寫(xiě): helloOurWorld

>>>

標(biāo)簽: 代碼

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:JDBC公共操作類(lèi)

下一篇: 經(jīng)典算法9:回溯法之0--1背包問(wèn)題