Python built-in data operations (1) --- string str, pythonstr
S. capitalize ()-> str Return a capitalized version of S, I. e. make the first character have upper case and the rest lower case.
Returns an upper-case string that converts the first letter of the string to the upper-case string, and the rest to the lower-case string.
S. casefold ()-> str Return a version of S suitable for caseless comparisons.
Returns a string suitable for case-insensitive comparison. In fact, it converts all uppercase letters into lowercase letters.
S. center (width [, fillchar])-> str width -- the total width of the string. Fillchar -- fill character. Return S centered in a string of length width. Padding is done using the specified fill character (default is a space)
Returns a string centered on the original string and filled with characters (fillchar) on both sides. The total length of the returned characters is width. If the length of the original string is greater than width, the original string is returned.
S. count (sub [, start [, end])-> int sub -- start and end of the substring -- start and end of the original string slice (INDEX) 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.
Returns the number of substrings that the original string contains within the range of the slice index. When start (end) is None, it starts from the beginning (to the end ).
S. encode (encoding = 'utf-8', errors = 'strict ')-> bytes encoding -- encoding format errors -- error handling scheme Encode S using the codec registered for encoding. default encoding is 'utf-8 '. errors may be given to set a different error handling scheme. default is 'strict 'meaning that encoding errors raisea UnicodeEncodeError. other possible values are 'ignore', 'replace 'and 'xmlcharrefreplace' as well as any other name registered with codecs. register_error that can handle UnicodeEncodeErrors.
The specified encoding is used to convert the string to bytes. encoding defaults to UTF-8, and errors refers to the processing scheme when an error occurs. By default, an error occurs in strict and UnicodeEncodeError is thrown. Other values include: ingnore, replace, and xmlcharrefreplace. These error handling methods can handle UnicodeEncodeError exceptions.
S. endswith (suffix [, start [, end])-> bool suffix -- suffix, a string or a string-based tuples, cannot be list start, end -- 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. if the original string ends with a suffix string or an element, True is returned; otherwise, False is returned. When start and end are not set to None, the original string is sliced with start and end. Suffix can be a string-based tuples.
S. expandtabs (tabsize = 8)-> str tabsize -- convert \ t to the number of spaces 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. if the original string remains unchanged, a copy string with \ t replaced by space is returned. By default, a \ t string is converted to eight spaces and can be modified using the tabsize parameter.
S. find (sub [, start [, end])-> int sub -- start, end -- same as 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. returns the smallest index of the substring. You can use start and end to find the shard. If the original string does not contain sub,-1 is returned.
S. format (* args, ** kwargs)-> str Return a formatted version of S, using substitutions from args and kwargs. the substitutions are identified by braces ('{' and '}'). place a placeholder character in the format of {} in the original string: When args is used, 0, 1, 2... and other indexes for formatting. For example, {0} and {1} correspond to the data with the index 0 and 1 in args respectively. When kwargs is used, the ing relationship is made through the dictionary, place the key in kwargs in {} and format the value corresponding to the key to the original string, for example, {'key1'} and {'key2'} correspond to the value values in kwargs = {'key1': 'value1 ', 'key2': 'value2'}.
Returns the formatted string.
S. format_map (mapping)-> str mapping -- ing relationship, that is, the ing of the dictionary format Return a formatted version of S, using substitutions from mapping. the substitutions are identified by braces ('{' and '}'). returns the formatted string, which is formatted in the same format as kwargs.
S. index (sub [, start [, end])-> int sub -- same as find start and end -- same as find Like S. find () but raise ValueError when the substring is not found. similar to the find function, ValueError is thrown when the original string does not contain sub.
S. isalnum ()-> bool Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise. returns the result of determining whether all strings are letters and numbers.
S. isalpha ()-> bool Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise. determines whether a string is composed of letters and returns the result.
S. isdecimal ()-> bool Return True if there are only decimal characters in S, False otherwise. checks whether the string contains only decimal characters and returns the judgment result. Used to judge unicode objects, such as u'123 '.
S. isdigit ()-> bool Return True if all characters in S are digits and there is at least one character in S, False otherwise. judge whether the string contains only numbers and Return the judgment result
S. isnumeric ()-> bool Return True if there are only numeric characters in S, False otherwise. checks whether the string contains only numeric characters and returns the judgment result
The differences between the isdecimal, isdigit, and isnumeric methods are as follows:
Isdigit () True: Unicode number, byte number (single byte), full-angle number (double byte), Rome digit False: Chinese Character number Error: No isdecimal () True: Unicode number ,, full-width numeric (dual-byte) False: Roman numerals, Chinese numerals Error: byte numeric (single-byte) isnumeric () True: Unicode digit, full-width numeric (dual-byte), roman numerals, chinese character number False: no Error: byte number (single byte)
A = '④ when Chapter VII then (vii) then'
Print (a. isnumeric ())
The result is still True, so numeric has the strongest recognition of the numbers in the characters. digit can be of the bytes type, and decimal can only recognize decimal.
S. isidentifier ()-> bool Return True if S is a valid identifier according to the language definition. use keyword. iskeyword () to test for reserved identifiers such as "def" and "class ". returns the result of determining whether the string is a python identifier. An identifier is a keyword that has been occupied, such as def and class. It serves the same purpose as the following built-in functions: import keyword. iskeyword ('def ')
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. Determine whether all strings are lowercase letters. The string must contain at least one letter.
S. isprintable ()-> bool Return True if all characters in S are considered printable in repr () or S is empty, False otherwise. returns True if the string is printable.
S. isspace ()-> bool Return True if all characters in S are whitespace and there is at least one character in S, False otherwise. determines whether all strings that are not empty are blank characters.
S. istitle ()-> bool Return True if S is a titlecased string and there is at least one character in S, I. e. upper-and titlecase characters may onlyfollow uncased characters and lowercase characters only cased ones. return False otherwise.
Determines whether non-null characters are in title format, that is, the first letter of each word is in upper case, and the other letters are in lower case. Each whitespace separated by spaces, tabs, and line breaks is considered a word. True is returned only when each word conforms to the format.
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. if all non-null strings are in uppercase, True is returned; otherwise, False is returned.
S. join (iterable)-> str iterable -- the string to be linked can be iterated. Return a string which is the concatenation of the strings in the iterable. the separator between elements is S. concatenate the elements in the iteratable parameter through the original string and return the concatenated string. The original string remains unchanged. If the parameter is a dictionary, the key of the dictionary is spliced and the splicing order is random.
S. ljust (width [, fillchar])-> str width -- total length of the filled character fillchar -- filled character, one character Return S left-justified in a Unicode string of length width. padding is done using the specified fill character (default is a space ). add a character to the end of the string and return it. Fillchar can only be one character. By default, it is a space.
S. lower ()-> str Return a copy of the string S converted to lowercase. Convert all characters in the string to lowercase letters and Return
S. lstrip ([chars])-> str chars -- Return a copy of the string S with leading whitespace removed. if chars is given and not None, remove characters in chars instead. after the string is copied, if the copy string starts with the chars character, the copy string is cleared and returned. Otherwise, the original string is directly returned.
Def maketrans (self, * args, ** kwargs) Return a translation table usable for str. translate (). if there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. character keys will be then converted to ordinals.
If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to th character at the same position in y.
If there is a third argument, it must be a string, whose characters will be mapped to None in the result. if there is only one parameter, it must be a dictionary mapped to a Unicode sequence (integer) or character to a Unicode sequence, string, or None. The character key is converted to a sequence. If there are two parameters, they must be strings of equal length. In the generated dictionary, each character in x will be mapped to the character at the same position in y. If there is a third parameter, it must be a string, and its character is mapped to None in the result. This function is only used to provide a ing table for the S. translate method.
S. partition (sep)-> (head, sep, tail) sep -- delimiter parameter, 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. search for the sep Separator in the character. If the string contains the sep sub-string, it returns a tuple that contains the separator, the separator, And the separator. If it does not contain, returns a triple that contains the original character and two empty strings.
S. replace (old, new [, count])-> str old -- the new character to be replaced -- the count to be replaced -- the number of replicas. The default value is None, replace all Return a copy of S with all occurrences of substring old replaced by new. if the optional argument count is given, only the first count occurrences are replaced. replace the child string of a copy of the original character, replace the old parameter character with the new parameter character, and replace all when the count is None. Otherwise, replace the count with several times, the copy string is returned. If the original string does not contain the old character, the original string is returned.
S. rfind (sub [, start [, end])-> int sub, start, end -- 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. in the target string or its slice string, locate the Index containing the sub-string from right to left and return the index value (forward index). If the index does not contain the sub-string, -1 is returned.
S.rindex(sub[, start[, end]]) -> int
Sub, start, end -- same as find Method
Like S. rfind () but raise ValueError when the substring is not found.
This function is the same as rfind. However, if the original string does not contain the sub string, A ValueError exception is thrown.
S. fill ust (width [, fillchar])-> str Return S right-justified in a string of length width. Padding is done using the specified fill character (default is a space ).
Similar to ljust, the filling direction is the opposite.
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.
Similar to partition, r indicates right. The difference is to find the first one and separate it.
S. rsplit (sep = None, maxsplit =-1)-> list of strings
Sep -- string to be separated
Maxsplit --
Return a list of the words in 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, any whitespace string is a separator.
Remove the sep string from the right to the left, and return the several parts separated by the removed sep as the tuples. When sep = None, the space is used as sep, and maxsplit is used as the number of large deletions. By default, all are removed. Note that if the original string contains an adjacent sep string, ''will appear in the element of the returned tuples.
S. rstrip ([chars])-> str
Chars -- characters to be cleared
Return a copy of the string S with trailing whitespace removed. If chars is given and not None, remove characters in chars instead.
Similar to lstrip, the difference is to clear chars at the end.
S. split (sep = None, maxsplit =-1)-> list of strings Return a list of the words in 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.
Similar to rsplit, the difference is to execute from left to right. Note that the return values of the two methods are the same when all values are replaced.
S. splitlines ([keepends])-> list of strings Return a list of the lines in S, breaking at line boundaries. line breaks are not supported ded in the resulting list unless keepends is given and true.
Separate strings by/n line breaks and return the list of separated strings. If the string does not contain \ n, a list of elements with the original string is returned.
S. startswith (prefix [, start [, end])-> bool
Prefix -- a parameter used for judgment. It can be a string or a string consisting of tuples, not a list.
Start and end -- same as endswith 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.
Determines whether a character or character slice starts with a prefix or a prefix element and returns a judgment result.
S. strip ([chars])-> str chars -- 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. copy the original string, and perform the margin removal operation on the header and tail of the copy string and return the result. If the chars parameter is not empty, the chars character is removed and the result is returned.
S. swapcase ()-> str Return a copy of S with uppercase characters converted to lowercase and vice versa. copy a string and change the lowercase letters to uppercase letters, and the uppercase letters to lowercase letters to return results.
S. title ()-> str Return a titlecased version of S, I. e. words start with title case characters, all remaining cased characters have lower case. convert the string into the title format, that is, the first letter of each word in upper case, the other letters in lower case, and return the result. Words are separated by blank characters.
S. translate (table)-> str table -- maptable, which is generally the maketrans object described above Return a copy of the string S in which each character has been mapped through the given translation table.
The table must implement lookup/indexing via _ getitem __, for instance a dictionary or list, Unicode ing Unicode ordinals to Unicode ordinals, strings, or None.
If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
S. upper ()-> str Return a copy of S converted to uppercase. Convert all characters of string copy into uppercase and then Return.
S. zfill (width)-> str width -- Pad a numeric string S with zeros on the left, to fill a field of the specified width. the string S is never truncated. fill the string with 0 on the left of the original string (numeric string), and return the string length after width is filled.