Movatterモバイル変換
[0]ホーム
2.2.6.1 String Methods
These are the string methods which both 8-bit strings and Unicodeobjects support:
- capitalize()
- Return a copy of the string with only its first character capitalized.
- center(width)
- Return centered in a string of lengthwidth. Padding is doneusing spaces.
- count(sub[, start[, end]])
- Return the number of occurrences of substringsub in stringS
[start:end]. Optional argumentsstart andend are interpreted as in slice notation.
- decode([encoding[, errors]])
- Decodes the string using the codec registered forencoding.encoding defaults to the default string encoding.errorsmay be given to set a different error handling scheme. The default is
'strict', meaning that encoding errors raiseValueError. Other possible values are'ignore' andreplace'.New in version 2.2.
- encode([encoding[,errors]])
- Return an encoded version of the string. Default encoding is the currentdefault string encoding.errors may be given to set a differenterror handling scheme. The default forerrors is
'strict', meaning that encoding errors raise aValueError. Other possible values are'ignore' and'replace'.New in version 2.0.
- endswith(suffix[, start[, end]])
- Return true if the string ends with the specifiedsuffix,otherwise return false. With optionalstart, test beginning atthat position. With optionalend, stop comparing at that position.
- expandtabs([tabsize])
- Return a copy of the string where all tab characters are expandedusing spaces. Iftabsize is not given, a tab size of
8characters is assumed.
- find(sub[, start[, end]])
- Return the lowest index in the string where substringsub isfound, such thatsub is contained in the range [start,end). Optional argumentsstart andend areinterpreted as in slice notation. Return
-1 ifsub isnot found.
- index(sub[, start[, end]])
- Likefind(), but raiseValueError when thesubstring is not found.
- isalnum()
- Return true if all characters in the string are alphanumeric and thereis at least one character, false otherwise.
- isalpha()
- Return true if all characters in the string are alphabetic and thereis 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 andthere is at least one cased character, false otherwise.
- isspace()
- Return true if there are only whitespace characters in the string andthe string is not empty, false otherwise.
- istitle()
- Return true if the string is a titlecased string: uppercasecharacters may only follow uncased characters and lowercase charactersonly cased ones. Return false otherwise.
- isupper()
- Return true if all cased characters in the string are uppercase andthere is at least one cased character, false otherwise.
- join(seq)
- Return a string which is the concatenation of the strings in thesequenceseq. The separator between elements is the stringproviding this method.
- ljust(width)
- Return the string left justified in a string of lengthwidth.Padding is done using spaces. The original string is returned ifwidth is less than
len(s).
- lower()
- Return a copy of the string converted to lowercase.
- lstrip([chars])
- Return a copy of the string with leading characters removed. Ifchars is omitted or
None, whitespace characters areremoved. If given and notNone,chars must be a string;the characters in the string will be stripped from the beginning ofthe string this method is called on.Changed in version 2.2.2:Support for thechars argument.
- replace(old, new[, maxsplit])
- Return a copy of the string with all occurrences of substringold replaced bynew. If the optional argumentmaxsplit is given, only the firstmaxsplit occurrences arereplaced.
- rfind(sub[,start[,end]])
- Return the highest index in the string where substringsub isfound, such thatsub is contained within s[start,end]. Optionalargumentsstart andend are interpreted as in slicenotation. Return
-1 on failure.
- rindex(sub[, start[, end]])
- Likerfind() but raisesValueError when thesubstringsub is not found.
- rjust(width)
- Return the string right justified in a string of lengthwidth.Padding is done using spaces. The original string is returned ifwidth is less than
len(s).
- rstrip([chars])
- Return a copy of the string with trailing characters removed. Ifchars is omitted or
None, whitespace characters areremoved. If given and notNone,chars must be a string;the characters in the string will be stripped from the end of thestring this method is called on.Changed in version 2.2.2:Support for thechars argument.
- split([sep[,maxsplit]])
- Return a list of the words in the string, usingsep as thedelimiter string. Ifmaxsplit is given, at mostmaxsplitsplits are done. Ifsep is not specified or
None, anywhitespace string is a separator.
- splitlines([keepends])
- Return a list of the lines in the string, breaking at lineboundaries. Line breaks are not included in the resulting list unlesskeepends is given and true.
- startswith(prefix[, start[, end]])
- Return true if string starts with theprefix, otherwisereturn false. With optionalstart, test string beginning atthat position. With optionalend, stop comparing string at thatposition.
- strip([chars])
- Return a copy of the string with leading and trailing charactersremoved. Ifchars is omitted or
None, whitespacecharacters are removed. If given and notNone,charsmust be a string; the characters in the string will be stripped fromthe both ends of the string this method is called on.Changed in version 2.2.2:Support for thechars argument.
- swapcase()
- Return a copy of the string with uppercase characters converted tolowercase and vice versa.
- title()
- Return a titlecased version of the string: words start with uppercasecharacters, all remaining cased characters are lowercase.
- translate(table[, deletechars])
- Return a copy of the string where all characters occurring in theoptional argumentdeletechars are removed, and the remainingcharacters have been mapped through the given translation table, whichmust be a string of length 256.
- upper()
- Return a copy of the string converted to uppercase.
- zfill(width)
- Return the numeric string left filled with zeros in a stringof lengthwidth. The original string is returned ifwidth is less than
len(s).New in version 2.2.2.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭