码迷,mamicode.com
首页 > 编程语言 > 详细

python str

时间:2017-08-07 20:48:27      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:index   als   default   默认   errors   self   arch   set   object   

capitalize(...)
 |      S.capitalize() -> string
 |      #-字符串首字母大写-
 |      Return a copy of the string S with only its first character
 |      capitalized.
 |  
 |  center(...)
 |      S.center(width[, fillchar]) -> string
 |      #字符串居中,width表示修改后字符串总长度,fillchar表示多余的长度位置填充什么样的字符:比如‘&’,‘1’,等字符或符号。
 |      Return S centered in a string of length width. Padding is
 |      done using the specified fill character (default is a space)
 |  
 |  count(...)
 |      S.count(sub[, start[, end]]) -> int
 |      #统计字符串中你需要查找的字符在句子中出现的次数,可以是单个字符也可以是一个单词短语。
 |      Return the number of non-overlapping occurrences of substring sub in
 |      string S[start:end].  Optional arguments start and end are interpreted
 |      as in slice notation.

 decode(...)
 |      S.decode([encoding[,errors]]) -> object
 |      #解码:unicode  utf-8 gbk 等编码的中文识别。unicode 万国码,utf-8 Python 默认编码,GBK Windows编码
          python---->windows     unicode=decode(‘utf-8‘)        gbk=unicode(‘gbk‘) 
 |      Decodes S using the codec registered for encoding. encoding defaults
 |      to the default encoding. errors may be given to set a different error
 |      handling scheme. Default is ‘strict‘ meaning that encoding errors raise
 |      a UnicodeDecodeError. Other possible values are ‘ignore‘ and ‘replace‘
 |      as well as any other name registered with codecs.register_error that is
 |      able to handle UnicodeDecodeErrors.
 |  
 |  encode(...)
 |      S.encode([encoding[,errors]]) -> object
 |      #编码 与解码相反
 |      Encodes S using the codec registered for encoding. encoding defaults
 |      to the default encoding. errors may be given to set a different error
 |      handling scheme. Default is ‘strict‘ meaning that encoding errors raise
 |      a UnicodeEncodeError. Other possible values are ‘ignore‘, ‘replace‘ and
 |      ‘xmlcharrefreplace‘ as well as any other name registered with
 |      codecs.register_error that is able to handle UnicodeEncodeErrors.
  
endswith(...)
 |      S.endswith(suffix[, start[, end]]) -> bool
 |      #判断是否由你确定的字符或字符串结尾,并且可以自由选择原句的长度和结尾位置。  
 |      Return True if S ends with the specified suffix, False otherwise.
 |      With optional start, test S beginning at that position.
 |      With optional end, stop comparing S at that position.
 |      suffix can also be a tuple of strings to try.
 |  
 |  expandtabs(...)
 |      S.expandtabs([tabsize]) -> string
 |      #将TAB空格转换成8个相应的空格
 |      Return a copy of S where all tab characters are expanded using spaces.
 |      If tabsize is not given, a tab size of 8 characters is assumed.
 |  
 |  find(...)
 |      S.find(sub [,start [,end]]) -> int
 |      #查找字符串中的字符或短句,返回找到的第一个字符或短句的位置信息,未找到返回-1
 |      Return the lowest index in S where substring sub is found,
 |      such that sub is contained within s[start:end].  Optional
 |      arguments start and end are interpreted as in slice notation.
 |      
 |      Return -1 on failure.
    
    format(...)
 |      #格式化输入/输出   比如:print  ‘{0}************{1}’.format(‘s‘,‘b‘)
        S.format(*args, **kwargs) -> string
 |  
 |  index(...)
  #同find函数,不同之处未找到就报错。
 |      S.index(sub [,start [,end]]) -> int
 |      
 |      Like S.find() but raise ValueError when the substring is not found.
 |  
 |  isalnum(...)
   #判断字符串是否只含字母和数字字符,是返回True否返回Flase
 |      S.isalnum() -> bool
 |      
 |      Return True if all characters in S are alphanumeric
 |      and there is at least one character in S, False otherwise.
 |  
 |  isalpha(...)
  #判断字符串是否只含字母
 |      S.isalpha() -> bool
 |      
 |      Return True if all characters in S are alphabetic
 |      and there is at least one character in S, False otherwise.
 |  
 |  isdigit(...)
   #判断字符串中是否只含数字字符
 |      S.isdigit() -> bool
 |      
 |      Return True if all characters in S are digits
 |      and there is at least one character in S, False otherwise.

   islower(...)

     #判断字符串中的字母是否全部是小写
| S.islower() -> bool
|
| Return True if all cased characters in S are lowercase and there is
| at least one cased character in S, False otherwise.
|
|  isspace(...)

   #判断字符串里是否全部是空格,全空格返回True
| S.isspace() -> bool
|
| Return True if all characters in S are whitespace
| and there is at least one character in S, False otherwise.
|
|  istitle(...)

   #判断字符串中首字母是否是大写并且其余字母小写
| S.istitle() -> bool
|
| Return True if S is a titlecased string and there is at least one
| character in S, i.e. uppercase characters may only follow uncased
| characters and lowercase characters only cased ones. Return False
| otherwise.

isupper(...)

#判断是否全部是大写
| S.isupper() -> bool

| Return True if all cased characters in S are uppercase and there is
| at least one cased character in S, False otherwise.
|
| join(...)

#将多个字符或字符串组合成一个字符串。如 ‘ ’.join(s)
| S.join(iterable) -> string
|
| Return a string which is the concatenation of the strings in the
| iterable. The separator between elements is S.
|
| ljust(...)

  #左对齐,右填充字符。同center
| S.ljust(width[, fillchar]) -> string
|
| Return S left-justified in a string of length width. Padding is
| done using the specified fill character (default is a space).
|
| lower(...)

  #全部转小写
| S.lower() -> string
|
| Return a copy of the string S converted to lowercase.

 lstrip(...)

#strip()为去掉字符串前后的空格,lstrip与rstrip为去掉左端或者右端的空格
| S.lstrip([chars]) -> string or unicode
|
| Return a copy of the string S with leading whitespace removed.
| If chars is given and not None, remove characters in chars instead.
| If chars is unicode, S will be converted to unicode before stripping

partition(...)

#它用来根据指定的分隔符将字符串进行分割,如果字符串包含指定的分隔符,则返回一个3元的tuple,第一个为分隔符左边的子串,第二个为分隔符本身,第三个为分隔符右边的子串。第二个例子说明,如果找不到指定的分隔符,则返回仍然是一个3元的tuple,第一个为整个字符串,第二和第三个为空串。

它与split(sep, 1)有什么区别呢?首先split返回的可能不是固定长度的返回值,它返回的是一个list,如果找到,则返回一个2元list,如果没找到,则返回一个1元的list,如:

>>> ‘a.b.c’.split(‘,’, 1)
[‘a.b.c‘]
>>> ‘a.b.c’.split(‘.’, 1)
[‘a‘, ‘b.c‘]


| S.partition(sep) -> (head, sep, tail)
|
| Search for the separator sep in S, and return the part before it,
| the separator itself, and the part after it. If the separator is not
| found, return S and two empty strings.
|
| replace(...)

#字符串替换。例如:s.replace(‘a‘,‘b‘)将字符串中的‘a‘全部替换成‘b’
| S.replace(old, new[, count]) -> string
|
| Return a copy of string S with all occurrences of substring
| old replaced by new. If the optional argument count is
| given, only the first count occurrences are replaced.
|
| rfind(...)

#从右开始查找,未找到返回-1
| S.rfind(sub [,start [,end]]) -> int
|
| Return the highest index in S where substring sub is found,
| such that sub is contained within s[start:end]. Optional
| arguments start and end are interpreted as in slice notation.
|
| Return -1 on failure.

rindex(...)

#从右开始。。。同index
| S.rindex(sub [,start [,end]]) -> int
|
| Like S.rfind() but raise ValueError when the substring is not found.
|
| rjust(...)

#从右开始
| S.rjust(width[, fillchar]) -> string
|
| Return S right-justified in a string of length width. Padding is
| done using the specified fill character (default is a space)
|
| rpartition(...)

#从右开始
| S.rpartition(sep) -> (head, sep, tail)
|
| Search for the separator sep in S, starting at the end of S, and return
| the part before it, the separator itself, and the part after it. If the
| separator is not found, return two empty strings and S.

rsplit(...)

#从右开始分割,默认以空格,或者可以在括号内写分割要求。例如split(‘o‘,2) 代表用O作为分割位,切2次。
| S.rsplit([sep [,maxsplit]]) -> list of strings
|
| Return a list of the words in the string S, using sep as the
| delimiter string, starting at the end of the string and working
| to the front. If maxsplit is given, at most maxsplit splits are
| done. If sep is not specified or is None, any whitespace string
| is a separator.

rstrip(...)

#移除字符串头尾指定的字符(默认为空格)
| S.rstrip([chars]) -> string or unicode
|
| Return a copy of the string S with trailing whitespace removed.
| If chars is given and not None, remove characters in chars instead.
| If chars is unicode, S will be converted to unicode before stripping
|
| split(...)

#将字符串分割成列表,默认以空格分割
| S.split([sep [,maxsplit]]) -> list of strings
|
| Return a list of the words in the string S, using sep as the
| delimiter string. If maxsplit is given, at most maxsplit
| splits are done. If sep is not specified or is None, any
| whitespace string is a separator and empty strings are removed
| from the result.

splitlines(...)


| S.splitlines([keepends]) -> list of strings
|
| Return a list of the lines in S, breaking at line boundaries.
| Line breaks are not included in the resulting list unless keepends
| is given and true.
|
| startswith(...)
| S.startswith(prefix[, start[, end]]) -> bool
|
| Return True if S starts with the specified prefix, False otherwise.
| With optional start, test S beginning at that position.
| With optional end, stop comparing S at that position.
| prefix can also be a tuple of strings to try.
|
| strip(...)
| S.strip([chars]) -> string or unicode
|
| Return a copy of the string S with leading and trailing
| whitespace removed.
| If chars is given and not None, remove characters in chars instead.
| If chars is unicode, S will be converted to unicode before stripping

python str

标签:index   als   default   默认   errors   self   arch   set   object   

原文地址:http://www.cnblogs.com/yebin17937901/p/7300803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!