Python基础教程笔记——第3章:使用字符串

      字符串是不可修改的,标准序列操作(索引,分片,判断成员资格,求长度,取最大值

最小值)对字符串都是有效的。

      格式化字符串,类似于C语言的输出是的感觉。

>>> format="hello %s   %s are you ok?"

>>> value=("yanliang","24")

>>> print(format % value)

hello yanliang   24 are you ok?

      find函数  a.find(s) >>> a.find('s',2) 设定了搜索的起始点  >>> a.find('s',1,2) 设置了起始点和结束点

      join函数  >>> sep='+' >>> seq=['1','2','3','4','5'] >>> sep.join(seq) 将sep分别的插入到seq中间

                    ‘1+2+3+4+5’                  

      lower函数 >>> a="HHGHGJ" >>> a.lower()  'hhghgj' 返回字符串的小写字母版

      replace函数  >>> a="HHGHGJ"  >>> a.replace('H','h')  'hhGhGJ' 将字符串中的H都用h代替

      split函数  join的逆方法,将字符串分割成片

                    >>> a='1+2+3+4+5'    >>> a.split('+')  ['1', '2', '3', '4', '5']

      strip函数  删除字符串两侧(不包括内部)空的字符串

                    >>> a='asi  '  >>> a.strip()  'asi'

      translate函数 

      

  

      

原文地址:https://www.cnblogs.com/yanliang12138/p/4695154.html