python大小写转换if_python代码实例大小写转换,首字母大写,去除特殊字符
下面是編程之家 jb51.cc 通過網絡收集整理的代碼片段。
編程之家小編現在分享給大家,也給大家做個參考。
#字母大小寫轉換
#首字母轉大寫
#去除字符串中特殊字符(如:'_','.',',',';'),然后再把去除后的字符串連接起來
#去除'hello_for_our_world'中的'_',并且把從第一個'_'以后的單詞首字母大寫
low_strs = 'abcd'
uper_strs = 'DEFG'
test_strA = 'hello_world'
test_strB = 'goodBoy'
test_strC = 'hello_for_our_world'
test_strD = 'hello__our_world_'
#小寫轉大寫
low_strs = low_strs.upper()
print('abcd小寫轉大寫:',low_strs)
#大寫轉小寫
uper_strs = uper_strs.lower()
print('DEFG大寫轉小寫:',uper_strs)
#只大寫第一個字母
test_strB = test_strB[0].upper() + test_strB[1:]
print('goodBoy只大寫第一個字母:',test_strB)
#去掉中間的'_',其他符號都是可以的,如:'.',',',';'
test_strA = ''.join(test_strA.split('_'))
print('hello_world去掉中間的\'_\':',test_strA)
#去除'hello_for_our_world'中的'_',并且把從第一個'_'以后的單詞首字母大寫
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\'中的\'_\',并且把從第一個\'_\'以后的單詞首字母大寫:',get_str(test_strC,'_'))
print('去除\'hello__our_world_\'中的\'_\',get_str(test_strD,'_'))
以上是編程之家(jb51.cc)為你收集整理的全部代碼內容,希望文章能夠幫你解決所遇到的程序開發問題。
如果覺得編程之家網站內容還不錯,歡迎將編程之家網站推薦給程序員好友。
總結
以上是生活随笔為你收集整理的python大小写转换if_python代码实例大小写转换,首字母大写,去除特殊字符的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python分析犯罪数据_使用 Spar
- 下一篇: php嗅探木马,PHP安全-密码嗅探