Python string built-in functions

Source: Internet
Author: User

Method description
String. capitalize () upper-case the first character of the string
String. center (width) returns a new string with the original string centered and filled with spaces to the length width.
String. count (str, beg = 0, end = len (string) returns the number of occurrences of str in string. If beg or end is specified, the number of occurrences of str in the specified range is returned.
String. decode (encoding = 'utf-8', errors = 'strict ') decodes a string in the encoding format specified by encoding. If an error occurs, an exception of ValueError is reported by default, unless errors specifies 'ignore' or
'Replace'
String. encode (encoding = 'utf-8', errors = 'strict ') is encoded as a string in the encoding format specified by encoding. If an error occurs, an exception of ValueError is reported by default, unless errors specifies 'ignore' or 'replace'
String. endswith (obj, beg = 0, end = len (string) checks whether the string ends with obj. If beg or end is specified, checks whether the specified range ends with obj, if yes, True is returned; otherwise, False is returned.
String. expandtabs (tabsize = 8) converts the tab character in string into a space. The default number of spaces tabsize is 8.
String. find (str, beg = 0, end = len (string) checks whether str is contained in a string. If beg and end are within the specified range, check whether it is included in the specified range, if the start index value is returned, otherwise
Return-1
String. index (str, beg = 0, end = len (string) is the same as the find () method, except that if str is not in string, an exception is reported.
String. isalnum () returns True if the string contains at least one character and all characters are letters or numbers. Otherwise, False is returned.
String. isalpha () returns True if the string contains at least one character and all characters are letters. Otherwise, False is returned.
String. isdecimal () If string only contains decimal digits, True is returned; otherwise, False is returned.
String. isdigit () If string only contains numbers, True is returned; otherwise, False is returned.
String. islower () if the string contains at least one case sensitive character and all these (case sensitive) characters are in lower case, True is returned; otherwise, False is returned.
String. isnumeric () If string contains only numeric characters, True is returned; otherwise, False is returned.
String. isspace () if the string contains only spaces, True is returned; otherwise, False is returned.
String. istitle () returns True if string is title (see title (); otherwise, False.
String. isupper () if the string contains at least one case sensitive character and all these (case sensitive) characters are uppercase, True is returned; otherwise, False is returned.
String. join (seq) Merges (concatenates) combines all elements in seq (represented by strings) into a new string using string as the separator.
String. ljust (width) returns a new string with the left alignment of the original string and fills in the width with spaces.
String. lower () converts all uppercase characters in string to lowercase.
String. lstrip () truncates spaces on the left of string.
String. partition (str) is a bit like a combination of find () and split (). Starting from the first position of str, the string is divided into a 3-element metagroup.
(String_pre_str, str, string_post_str). If the string does not contain str, string_pre_str = string.
String. replace (str1, str2, num = string. count (str1) replace str1 in string with str2. If num is specified, it cannot exceed num.
String. rfind (str, beg = 0, end = len (string) is similar to the find () function, but it is searched from the right.
String. rindex (str, beg = 0, end = len (string) is similar to index (), but starts from the right.
String. Adjust ust (width) returns a new string with the right alignment of the original string and fills in the width with spaces.
String. rpartition (str) is similar to the partition () function, but it is searched from the right.
String. rstrip () removes spaces at the end of the string.
String. split (str = "", num = string. count (str) slices string with str as the separator. If num has a specified value, only the num sub-string is separated.
String. splitlines (num = string. count ('\ n') are separated by rows. a list containing rows as elements is returned. If num is specified, only num rows are sliced.
String. startswith (obj, beg = 0, end = len (string) checks whether the string starts with obj. If yes, True is returned. Otherwise, False is returned. If the beg and end values are specified, check within the specified range.
String. strip ([obj]): Execute lstrip () and rstrip () on string ()
String. swapcase () Flip case in string
String. title () returns the title string, that is, all words start with uppercase, And the other letters are lowercase (see istitle ())
String. translate (str, del = "") converts string Characters Based on the table (including 256 characters) given by str. The characters to be filtered out are placed in the del parameter.
String. upper () converts lowercase letters in string to uppercase letters.
String. zfill (width) returns the string with the length of width. The original string is right aligned and filled with 0.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.