python字符串大小写如何转换

  介绍

这篇文章将为大家详细讲解有关python字符串大小写如何转换,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

字符串可能是我们实际开发中用的最多的数据类型了,关于字符串有很多的使用方法,如大小写转换,分割,增加,替换等。下面说一下常用的字符串大小写转换的方法。

总结我们在平常开发过程中对字符串的一些操作:

#字母大小写转换   #首字母转大写   #去除字符串中特殊字符(如:& # 39;_ # 39;,& # 39;强生# 39;,& # 39;,& # 39;,& # 39;;& # 39;),然后再把去除后的字符串连接起来   #去除& # 39;hello_for_our_world& # 39;中的& # 39;_ # 39;,并且把从第一个& # 39;_ # 39;以后的单词首字母大写

代码实例:

#字母大小写转换   #首字母转大写   #去除字符串中特殊字符(如:& # 39;_ # 39;,& # 39;强生# 39;,& # 39;,& # 39;,& # 39;;& # 39;),然后再把去除后的字符串连接起来   #去除& # 39;hello_for_our_world& # 39;中的& # 39;_ # 39;,并且把从第一个& # 39;_ # 39;以后的单词首字母大写   low_strs=, & # 39; abcd # 39;   uper_strs=, & # 39; DEFG& # 39;   test_strA=, & # 39; hello_world # 39;   test_strB=, & # 39; goodBoy& # 39;   test_strC=, & # 39; hello_for_our_world& # 39;   test_strD=, & # 39; hello__our_world_& # 39;   ,,   #小写转大写   low_strs=, low_strs.upper ()   打印(& # 39;abcd小写转大写:& # 39;,,low_strs)   ,,   #大写转小写   uper_strs=, uper_strs.lower ()   打印(& # 39;DEFG大写转小写:& # 39;,,uper_strs)   ,,   #只大写第一个字母   test_strB=, test_strB [0] .upper () +, test_strB [1:]   打印(& # 39;goodBoy只大写第一个字母:& # 39;,,test_strB)   ,,   #去掉中间的& # 39;_ # 39;,其他符号都是可以的,如:& # 39;强生# 39;& # 39;& # 39;& # 39;;& # 39;   test_strA=, & # 39; & # 39; . join (test_strA.split (& # 39; _ # 39;))   打印(& # 39;hello_world去掉中间的\ & # 39;_ \ & # 39;:& # 39;,,test_strA)   ,,   #去除& # 39;hello_for_our_world& # 39;中的& # 39;_ # 39;,并且把从第一个& # 39;_ # 39;以后的单词首字母大写   def  get_str (oriStr splitStr):   ,,,str_list=, oriStr.split (splitStr)   ,,,if  len (str_list),在1:   ,,,,,,,for  indexin 范围(len (str_list)):   ,,,,,,,,,,,if  str_list(指数),!=,& # 39;& # 39;:   ,,,,,,,,,,,,,,,str_list(指数)=,str_list(指数)[0].upper () +, str_list(指数)[1:]   ,,,,,,,,,,,其他的:   ,,,,,,,,,,,,,,,继续   ,,,,,,,return  & # 39; & # 39; . join (str_list)   ,,,:   ,,,,,,,return  oriStr   ,,   打印(& # 39;去除\ & # 39;hello_for_our_world \ & # 39;中的\ & # 39;_ \ & # 39;,并且把从第一个\ & # 39;_ \ & # 39;以后的单词首字母大写:& # 39;,,get_str (test_strC & # 39; _ # 39;))   印刷(& # 39;去除\ & # 39;hello__our_world_ \ & # 39;中的\ & # 39;_ \ & # 39;,并且把从第一个\ & # 39;_ \ & # 39;以后的单词首字母大写:& # 39;,,get_str (test_strD & # 39; _ # 39;))

关于python字符串大小写如何转换就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看的到。

python字符串大小写如何转换