自带帮助文档:
1 Python 3.6.3 (v3.6.3:2c5fed86e0, Oct 3 2017, 00:32:08) 2 [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin 3 Type "copyright", "credits" or "license()" for more information. 4 >>> help(str) 5 Help on class str in module builtins: 6 7 class str(object) 8 | str(object=‘‘) -> str 9 | str(bytes_or_buffer[, encoding[, errors]]) -> str 10 | 11 | Create a new string object from the given object. If encoding or 12 | errors is specified, then the object must expose a data buffer 13 | that will be decoded using the given encoding and error handler. 14 | Otherwise, returns the result of object.__str__() (if defined) 15 | or repr(object). 16 | encoding defaults to sys.getdefaultencoding(). 17 | errors defaults to ‘strict‘. 18 | 19 | Methods defined here: 20 | 21 | __add__(self, value, /) 22 | Return self+value. 23 | 24 | __contains__(self, key, /) 25 | Return key in self. 26 | 27 | __eq__(self, value, /) 28 | Return self==value. 29 | 30 | __format__(...) 31 | S.__format__(format_spec) -> str 32 | 33 | Return a formatted version of S as described by format_spec. 34 | 35 | __ge__(self, value, /) 36 | Return self>=value. 37 | 38 | __getattribute__(self, name, /) 39 | Return getattr(self, name). 40 | 41 | __getitem__(self, key, /) 42 | Return self[key]. 43 | 44 | __getnewargs__(...) 45 | 46 | __gt__(self, value, /) 47 | Return self>value. 48 | 49 | __hash__(self, /) 50 | Return hash(self). 51 | 52 | __iter__(self, /) 53 | Implement iter(self). 54 | 55 | __le__(self, value, /) 56 | Return self<=value. 57 | 58 | __len__(self, /) 59 | Return len(self). 60 | 61 | __lt__(self, value, /) 62 | Return self<value. 63 | 64 | __mod__(self, value, /) 65 | Return self%value. 66 | 67 | __mul__(self, value, /) 68 | Return self*value.n 69 | 70 | __ne__(self, value, /) 71 | Return self!=value. 72 | 73 | __new__(*args, **kwargs) from builtins.type 74 | Create and return a new object. See help(type) for accurate signature. 75 | 76 | __repr__(self, /) 77 | Return repr(self). 78 | 79 | __rmod__(self, value, /) 80 | Return value%self. 81 | 82 | __rmul__(self, value, /) 83 | Return self*value. 84 | 85 | __sizeof__(...) 86 | S.__sizeof__() -> size of S in memory, in bytes 87 | 88 | __str__(self, /) 89 | Return str(self). 90 | 91 | capitalize(...) 92 | S.capitalize() -> str 93 | 94 | Return a capitalized version of S, i.e. make the first character 95 | have upper case and the rest lower case. 96 | 97 | casefold(...) 98 | S.casefold() -> str 99 | 100 | Return a version of S suitable for caseless comparisons. 101 | 102 | center(...) 103 | S.center(width[, fillchar]) -> str 104 | 105 | Return S centered in a string of length width. Padding is 106 | done using the specified fill character (default is a space) 107 | 108 | count(...) 109 | S.count(sub[, start[, end]]) -> int 110 | 111 | Return the number of non-overlapping occurrences of substring sub in 112 | string S[start:end]. Optional arguments start and end are 113 | interpreted as in slice notation. 114 | 115 | encode(...) 116 | S.encode(encoding=‘utf-8‘, errors=‘strict‘) -> bytes 117 | 118 | Encode S using the codec registered for encoding. Default encoding 119 | is ‘utf-8‘. errors may be given to set a different error 120 | handling scheme. Default is ‘strict‘ meaning that encoding errors raise 121 | a UnicodeEncodeError. Other possible values are ‘ignore‘, ‘replace‘ and 122 | ‘xmlcharrefreplace‘ as well as any other name registered with 123 | codecs.register_error that can handle UnicodeEncodeErrors. 124 | 125 | endswith(...) 126 | S.endswith(suffix[, start[, end]]) -> bool 127 | 128 | Return True if S ends with the specified suffix, False otherwise. 129 | With optional start, test S beginning at that position. 130 | With optional end, stop comparing S at that position. 131 | suffix can also be a tuple of strings to try. 132 | 133 | expandtabs(...) 134 | S.expandtabs(tabsize=8) -> str 135 | 136 | Return a copy of S where all tab characters are expanded using spaces. 137 | If tabsize is not given, a tab size of 8 characters is assumed. 138 | 139 | find(...) 140 | S.find(sub[, start[, end]]) -> int 141 | 142 | Return the lowest index in S where substring sub is found, 143 | such that sub is contained within S[start:end]. Optional 144 | arguments start and end are interpreted as in slice notation. 145 | 146 | Return -1 on failure. 147 | 148 | format(...) 149 | S.format(*args, **kwargs) -> str 150 | 151 | Return a formatted version of S, using substitutions from args and kwargs. 152 | The substitutions are identified by braces (‘{‘ and ‘}‘). 153 | 154 | format_map(...) 155 | S.format_map(mapping) -> str 156 | 157 | Return a formatted version of S, using substitutions from mapping. 158 | The substitutions are identified by braces (‘{‘ and ‘}‘). 159 | 160 | index(...) 161 | S.index(sub[, start[, end]]) -> int 162 | 163 | Return the lowest index in S where substring sub is found, 164 | such that sub is contained within S[start:end]. Optional 165 | arguments start and end are interpreted as in slice notation. 166 | 167 | Raises ValueError when the substring is not found. 168 | 169 | isalnum(...) 170 | S.isalnum() -> bool 171 | 172 | Return True if all characters in S are alphanumeric 173 | and there is at least one character in S, False otherwise. 174 | 175 | isalpha(...) 176 | S.isalpha() -> bool 177 | 178 | Return True if all characters in S are alphabetic 179 | and there is at least one character in S, False otherwise. 180 | 181 | isdecimal(...) 182 | S.isdecimal() -> bool 183 | 184 | Return True if there are only decimal characters in S, 185 | False otherwise. 186 | 187 | isdigit(...) 188 | S.isdigit() -> bool 189 | 190 | Return True if all characters in S are digits 191 | and there is at least one character in S, False otherwise. 192 | 193 | isidentifier(...) 194 | S.isidentifier() -> bool 195 | 196 | Return True if S is a valid identifier according 197 | to the language definition. 198 | 199 | Use keyword.iskeyword() to test for reserved identifiers 200 | such as "def" and "class". 201 | 202 | islower(...) 203 | S.islower() -> bool 204 | 205 | Return True if all cased characters in S are lowercase and there is 206 | at least one cased character in S, False otherwise. 207 | 208 | isnumeric(...) 209 | S.isnumeric() -> bool 210 | 211 | Return True if there are only numeric characters in S, 212 | False otherwise. 213 | 214 | isprintable(...) 215 | S.isprintable() -> bool 216 | 217 | Return True if all characters in S are considered 218 | printable in repr() or S is empty, False otherwise. 219 | 220 | isspace(...) 221 | S.isspace() -> bool 222 | 223 | Return True if all characters in S are whitespace 224 | and there is at least one character in S, False otherwise. 225 | 226 | istitle(...) 227 | S.istitle() -> bool 228 | 229 | Return True if S is a titlecased string and there is at least one 230 | character in S, i.e. upper- and titlecase characters may only 231 | follow uncased characters and lowercase characters only cased ones. 232 | Return False otherwise. 233 | 234 | isupper(...) 235 | S.isupper() -> bool 236 | 237 | Return True if all cased characters in S are uppercase and there is 238 | at least one cased character in S, False otherwise. 239 | 240 | join(...) 241 | S.join(iterable) -> str 242 | 243 | Return a string which is the concatenation of the strings in the 244 | iterable. The separator between elements is S. 245 | 246 | ljust(...) 247 | S.ljust(width[, fillchar]) -> str 248 | 249 | Return S left-justified in a Unicode string of length width. Padding is 250 | done using the specified fill character (default is a space). 251 | 252 | lower(...) 253 | S.lower() -> str 254 | 255 | Return a copy of the string S converted to lowercase. 256 | 257 | lstrip(...) 258 | S.lstrip([chars]) -> str 259 | 260 | Return a copy of the string S with leading whitespace removed. 261 | If chars is given and not None, remove characters in chars instead. 262 | 263 | partition(...) 264 | S.partition(sep) -> (head, sep, tail) 265 | 266 | Search for the separator sep in S, and return the part before it, 267 | the separator itself, and the part after it. If the separator is not 268 | found, return S and two empty strings. 269 | 270 | replace(...) 271 | S.replace(old, new[, count]) -> str 272 | 273 | Return a copy of S with all occurrences of substring 274 | old replaced by new. If the optional argument count is 275 | given, only the first count occurrences are replaced. 276 | 277 | rfind(...) 278 | S.rfind(sub[, start[, end]]) -> int 279 | 280 | Return the highest index in S where substring sub is found, 281 | such that sub is contained within S[start:end]. Optional 282 | arguments start and end are interpreted as in slice notation. 283 | 284 | Return -1 on failure. 285 | 286 | rindex(...) 287 | S.rindex(sub[, start[, end]]) -> int 288 | 289 | Return the highest index in S where substring sub is found, 290 | such that sub is contained within S[start:end]. Optional 291 | arguments start and end are interpreted as in slice notation. 292 | 293 | Raises ValueError when the substring is not found. 294 | 295 | rjust(...) 296 | S.rjust(width[, fillchar]) -> str 297 | 298 | Return S right-justified in a string of length width. Padding is 299 | done using the specified fill character (default is a space). 300 | 301 | rpartition(...) 302 | S.rpartition(sep) -> (head, sep, tail) 303 | 304 | Search for the separator sep in S, starting at the end of S, and return 305 | the part before it, the separator itself, and the part after it. If the 306 | separator is not found, return two empty strings and S. 307 | 308 | rsplit(...) 309 | S.rsplit(sep=None, maxsplit=-1) -> list of strings 310 | 311 | Return a list of the words in S, using sep as the 312 | delimiter string, starting at the end of the string and 313 | working to the front. If maxsplit is given, at most maxsplit 314 | splits are done. If sep is not specified, any whitespace string 315 | is a separator. 316 | 317 | rstrip(...) 318 | S.rstrip([chars]) -> str 319 | 320 | Return a copy of the string S with trailing whitespace removed. 321 | If chars is given and not None, remove characters in chars instead. 322 | 323 | split(...) 324 | S.split(sep=None, maxsplit=-1) -> list of strings 325 | 326 | Return a list of the words in S, using sep as the 327 | delimiter string. If maxsplit is given, at most maxsplit 328 | splits are done. If sep is not specified or is None, any 329 | whitespace string is a separator and empty strings are 330 | removed from the result. 331 | 332 | splitlines(...) 333 | S.splitlines([keepends]) -> list of strings 334 | 335 | Return a list of the lines in S, breaking at line boundaries. 336 | Line breaks are not included in the resulting list unless keepends 337 | is given and true. 338 | 339 | startswith(...) 340 | S.startswith(prefix[, start[, end]]) -> bool 341 | 342 | Return True if S starts with the specified prefix, False otherwise. 343 | With optional start, test S beginning at that position. 344 | With optional end, stop comparing S at that position. 345 | prefix can also be a tuple of strings to try. 346 | 347 | strip(...) 348 | S.strip([chars]) -> str 349 | 350 | Return a copy of the string S with leading and trailing 351 | whitespace removed. 352 | If chars is given and not None, remove characters in chars instead. 353 | 354 | swapcase(...) 355 | S.swapcase() -> str 356 | 357 | Return a copy of S with uppercase characters converted to lowercase 358 | and vice versa. 359 | 360 | title(...) 361 | S.title() -> str 362 | 363 | Return a titlecased version of S, i.e. words start with title case 364 | characters, all remaining cased characters have lower case. 365 | 366 | translate(...) 367 | S.translate(table) -> str 368 | 369 | Return a copy of the string S in which each character has been mapped 370 | through the given translation table. The table must implement 371 | lookup/indexing via __getitem__, for instance a dictionary or list, 372 | mapping Unicode ordinals to Unicode ordinals, strings, or None. If 373 | this operation raises LookupError, the character is left untouched. 374 | Characters mapped to None are deleted. 375 | 376 | upper(...) 377 | S.upper() -> str 378 | 379 | Return a copy of S converted to uppercase. 380 | 381 | zfill(...) 382 | S.zfill(width) -> str 383 | 384 | Pad a numeric string S with zeros on the left, to fill a field 385 | of the specified width. The string S is never truncated. 386 | 387 | ---------------------------------------------------------------------- 388 | Static methods defined here: 389 | 390 | maketrans(x, y=None, z=None, /) 391 | Return a translation table usable for str.translate(). 392 | 393 | If there is only one argument, it must be a dictionary mapping Unicode 394 | ordinals (integers) or characters to Unicode ordinals, strings or None. 395 | Character keys will be then converted to ordinals. 396 | If there are two arguments, they must be strings of equal length, and 397 | in the resulting dictionary, each character in x will be mapped to the 398 | character at the same position in y. If there is a third argument, it 399 | must be a string, whose characters will be mapped to None in the result.