python代码实例大小写转换,首字母大写,去除特殊字符

python代码实例大小写转换,首字母大写,去除特殊字符,第1张

概述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代码实例大小写转换,首字母大写,去除特殊字符全部内容,希望文章能够帮你解决python代码实例大小写转换,首字母大写,去除特殊字符所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1199193.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存