python字符串函数

来源:互联网 发布:上海公务员备考知乎 编辑:程序博客网 时间:2024/06/01 07:39

python大小写转换函数:

1: capitalize()  #字符串首字母大写,其余全部小写

2: lower()  #字符串全部小写

3:casefold()  #字符串全部小写,与第二个作用基本类似


注:两者本质区别并不清楚,引用知乎上的答案,侵权立删!

作者:halfpot
链接:https://www.zhihu.com/question/34846132/answer/60095559
来源:知乎

“Casefolding is similar to lowercasing but more aggressive because it is intended to remove all case distinctions in a string. For example, the German lowercase letter '�' is equivalent to "ss". Since it is already lowercase, lower() would do nothing to '�';casefold() converts it to "ss"
casefold更具有攻击性,例如德国的小写字母'口'相当于'ss' ,因为他已经小写了,所有lower不会做什么,但是Casefold会将它变为'ss' 似乎有些懂了,但是还是不知道干嘛用的

4: upper()  #字符串全部大写

5: title()  #字符串中每个单词首字母大写,其余小写


python删除字符函数:

1:strip(str)   #删除字符串开头,结尾处中,位于str序列中的字符,str为空时默认删除空白符(包括'\n', '\r',  '\t',  ' ')

2:lstrip(str)  #删除字符串开头处,位于str序列中的字符

3:rstrip(str) #删除字符串结尾处,位于str序列中的字符

      举例说明:>>> a = '321fasjkfn53478123532'

                          >>> b = a.strip('123')
                          >>> b
                          'fasjkfn534781235'

                          >>> b = a.lstrip('123')

                          >>> b
                          'fasjkfn53478123532'

                          >>> b = a.rstrip('123')
                          >>> b
                          '321fasjkfn534781235'



0 0
原创粉丝点击