python 开发 |
您所在的位置:网站首页 › python转换为大写字母 › python 开发 |
去除特殊字符 这篇 blog 主要是总结我们在平常开发过程中对字符串的一些操作: # 字母大小写转换 # 首字母转大写 # 去除字符串中特殊字符 ( 如: '_' , '.' , ',' , ';') ,然后再把去除后的字符串连接起来 # 去除 'hello_for_our_world' 中的 '_', 并且把从第一个 '_' 以后的单词首字母大写 具体的代码 demo : 1 # 字母大小写转换 2 # 首字母转大写 3 # 去除字符串中特殊字符 ( 如: '_' , '.' , ',' , ';') ,然后再把去除后的字符串连接起来 4 # 去除 'hello_for_our_world' 中的 '_', 并且把从第一个 '_' 以后的单词首字母大写 5 low_strs = 'abcd' 6 uper_strs = 'DEFG' 7 test_strA = 'hello_world' 8 test_strB = 'goodBoy' 9 test_strC = 'hello_for_our_world' 10 test_strD = 'hello__our_world_' 11 12 # 小写转大写 13 low_strs = low_strs.upper() 14 print('abcd 小写转大写 :', low_strs) 15 16 # 大写转小写 17 uper_strs = uper_strs.lower() 18 print('DEFG 大写转小写: ', uper_strs) 19 20 # 只大写第一个字母 21 test_strB = test_strB[0].upper() + test_strB[1:] 22 print('goodBoy 只大写第一个字母 :', test_strB) 23 24 # 去掉中间的 '_', 其他符号都是可以的,如: '.' , ',' , ';' 25 test_strA = ''.join(test_strA.split('_')) 26 print('hello_world 去掉中间的 \'_\':', test_strA) 27 28 # 去除 'hello_for_our_world' 中的 '_', 并且把从第一个 '_' 以后的单词首字母大写 29 def get_str(oriStr,splitStr): 30 str_list = oriStr.split(splitStr) 31 if len(str_list) > 1: 32 for index in range(1, len(str_list)): 33 if str_list[index] != '': 34 str_list[index] = str_list[index][0].upper() + str_list[index][1:] 35 else: |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |