Python string built-in functions

Source: Internet
Author: User
String. capitalize () capital string of the first character of the string. center (width) returns a new string with the original string centered and filled with spaces to the length width. count (str, beg0, endlen (string) returns the number of occurrences of str in string. if beg or end is specified, return the number of occurrences of str in the specified range. decod... string. capitalize ()
Uppercase of the first character of the string

String. center (width)
Returns a new string with the original string centered and filled with spaces to the width.

String. count (str, beg = 0, end = len (string ))
Returns the number of occurrences of str in the 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 ')
String is encoded in the encoding format specified by encoding. If an error occurs,
ValueError exception, unless errors specifies 'ignore' or 'replace'

String. endswith (obj, beg = 0, end = len (string ))
Check whether the string ends with obj. if beg or end is specified, check whether the string ends with obj in the specified range. If yes, return True; otherwise, return False.

String. expandtabs (tabsize = 8)
Convert the tab character in string to a space. the default number of spaces tabsize is 8.

String. find (str, beg = 0, end = len (string ))
Checks whether str is included in the string. if beg and end are specified, checks whether the str is included in the specified range. If yes, returns the starting index value; otherwise, returns-1.

String. index (str, beg = 0, end = len (string ))
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, returns False.

String. isalpha ()
Returns True if the string contains at least one character and all characters are letters; otherwise, returns False.

String. isdecimal ()
Returns True if the string contains only decimal digits; otherwise, returns False.

String. isdigit ()
If the string contains only numbers, True is returned. otherwise, False is returned.

String. islower ()
True is returned if the string contains at least one case-sensitive character and all these (case-sensitive) characters are in lower case. otherwise, False is returned.

String. isnumeric ()
Returns True if string contains only numeric characters; otherwise, returns False.

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, returns False.

String. isupper ()
True is returned if the string contains at least one case-sensitive character and all these (case-sensitive) characters are uppercase. otherwise, False is returned.

String. join (seq)
Merges (concatenates) combines all elements (represented by strings) in seq 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 filled with spaces to the width.

String. lower ()
Converts all uppercase characters in string to lowercase.

String. lstrip ()
Truncates spaces on the left of the string.

String. partition (str)
It is a bit like the combination of find () and split (). starting from the first position of str, the string character string is divided into a 3-element group (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) replaces str1 in string with str2. if num is specified, it cannot exceed num.

String. rfind (str, beg = 0, end = len (string ))
Similar to the find () function, but the query starts from the right side.

String. rindex (str, beg = 0, end = len (string ))
Similar to index (), but starts from the right.

String. must UST (width)
Returns a new string with the right alignment of the original string and filled with spaces to the width.

String. rpartition (str)
Similar to the partition () function, but the query starts from the right side.

String. rstrip ()
Removes spaces at the end of a 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 '))
B and c are separated by rows. an element containing rows is returned.
. If num is specified, only num slices are sliced.
Line.
String. startswith (obj, beg = 0, end = len (string ))
Check 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])
Run lstrip () and rstrip () on string ()

String. swapcase ()
Flip case in string

String. title ()
Returns the title string, indicating that all words start with uppercase and the other letters are lowercase (see istitle ())

String. translate (str, del = "")
Convert string characters based on the table (including 256 characters) given by str, and put the characters to be filtered out into the del parameter

String. upper ()
Converts lowercase letters in string to uppercase letters.

String. zfill (width)
Returns a string with the length of width. the original string is right-aligned and prefilled.
0

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.