Copyright (C) 2000-2012 |
GNU Info (python2.1-lib.info)String MethodsString Methods .............. These are the string methods which both 8-bit strings and Unicode objects support: `capitalize()' Return a copy of the string with only its first character capitalized. `center(width)' Return centered in a string of length WIDTH. Padding is done using spaces. `count(sub[, start[, end]])' Return the number of occurrences of substring SUB in string S`[START:END]'. Optional arguments START and END are interpreted as in slice notation. `encode([encoding[,errors]])' Return an encoded version of the string. Default encoding is the current default string encoding. ERRORS may be given to set a different error handling scheme. The default for ERRORS is `'strict'', meaning that encoding errors raise a `ValueError'. Other possible values are `'ignore'' and `'replace''. _Added in Python version 2.0_ `endswith(suffix[, start[, end]])' Return true if the string ends with the specified SUFFIX, otherwise return false. With optional START, test beginning at that position. With optional END, stop comparing at that position. `expandtabs([tabsize])' Return a copy of the string where all tab characters are expanded using spaces. If TABSIZE is not given, a tab size of `8' characters is assumed. `find(sub[, start[, end]])' Return the lowest index in the string where substring SUB is found, such that SUB is contained in the range [START, END). Optional arguments START and END are interpreted as in slice notation. Return `-1' if SUB is not found. `index(sub[, start[, end]])' Like `find()', but raise `ValueError' when the substring is not found. `isalnum()' Return true if all characters in the string are alphanumeric and there is at least one character, false otherwise. `isalpha()' Return true if all characters in the string are alphabetic and there is at least one character, false otherwise. `isdigit()' Return true if there are only digit characters, false otherwise. `islower()' Return true if all cased characters in the string are lowercase and there is at least one cased character, false otherwise. `isspace()' Return true if there are only whitespace characters in the string and the string is not empty, false otherwise. `istitle()' Return true if the string is a titlecased string, i.e. uppercase characters may only follow uncased characters and lowercase characters only cased ones. Return false otherwise. `isupper()' Return true if all cased characters in the string are uppercase and there is at least one cased character, false otherwise. `join(seq)' Return a string which is the concatenation of the strings in the sequence SEQ. The separator between elements is the string providing this method. `ljust(width)' Return the string left justified in a string of length WIDTH. Padding is done using spaces. The original string is returned if WIDTH is less than `len(S)'. `lower()' Return a copy of the string converted to lowercase. `lstrip()' Return a copy of the string with leading whitespace removed. `replace(old, new[, maxsplit])' Return a copy of the string with all occurrences of substring OLD replaced by NEW. If the optional argument MAXSPLIT is given, only the first MAXSPLIT occurrences are replaced. `rfind(sub [,start [,end]])' Return the highest index in the string 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(sub[, start[, end]])' Like `rfind()' but raises `ValueError' when the substring SUB is not found. `rjust(width)' Return the string right justified in a string of length WIDTH. Padding is done using spaces. The original string is returned if WIDTH is less than `len(S)'. `rstrip()' Return a copy of the string with trailing whitespace removed. `split([sep [,maxsplit]])' Return a list of the words in the string, using SEP as the delimiter string. If MAXSPLIT is given, at most MAXSPLIT splits are done. If SEP is not specified or `None', any whitespace string is a separator. `splitlines([keepends])' Return a list of the lines in the string, breaking at line boundaries. Line breaks are not included in the resulting list unless KEEPENDS is given and true. `startswith(prefix[, start[, end]])' Return true if string starts with the PREFIX, otherwise return false. With optional START, test string beginning at that position. With optional END, stop comparing string at that position. `strip()' Return a copy of the string with leading and trailing whitespace removed. `swapcase()' Return a copy of the string with uppercase characters converted to lowercase and vice versa. `title()' Return a titlecased version of, i.e. words start with uppercase characters, all remaining cased characters are lowercase. `translate(table[, deletechars])' Return a copy of the string where all characters occurring in the optional argument DELETECHARS are removed, and the remaining characters have been mapped through the given translation table, which must be a string of length 256. `upper()' Return a copy of the string converted to uppercase. automatically generated by info2www version 1.2.2.9 |