Python string built-in method collation

Source: Internet
Author: User

The following table is organized by others when learning through online video. Put it here for later use.

Capitalize () Change the first character of a string to uppercase
Casefold () Change all characters of the entire string to lowercase
Center (width) Centers the string and fills the new string with a space of length width
Count (sub[, start[, end]]) Returns the number of occurrences of a sub within a string, with the start and end parameters representing the range, optional.
Encode (encoding= ' utf-8 ', errors= ' strict ') Encodes a string in the encoding format specified by encoding.
EndsWith (sub[, start[, end]]) Checks whether the string ends with a sub substring, or returns False if True. The start and end parameters represent ranges and are optional.
Expandtabs ([tabsize=8]) Converts the tab symbol (\ t) in a string to a space, such as not specifying a parameter, and the default number of spaces is tabsize=8.
Find (sub[, start[, end]]) Detects if the sub is contained in a string, returns the index value if any, otherwise returns the -1,start and end parameters to indicate the range, optional.
Index (sub[, start[, end]]) Same as the Find method, but an exception occurs if the sub is not in a string.
Isalnum () Returns True if the string has at least one character and all characters are letters or numbers, otherwise False is returned.
Isalpha () Returns True if the string has at least one character and all characters are letters, otherwise False is returned.
Isdecimal () Returns True if the string contains only decimal digits, otherwise False.
IsDigit () Returns True if the string contains only a number, otherwise False.
Islower () Returns True if the string contains at least one case-sensitive character, and the characters are lowercase, otherwise False.
IsNumeric () Returns True if the string contains only numeric characters, otherwise False is returned.
Isspace () Returns True if the string contains only spaces, otherwise False is returned.
Istitle () Returns True if the string is a caption (all words start with uppercase and the remaining letters are lowercase), otherwise False is returned.
Isupper () Returns True if the string contains at least one case-sensitive character, and the characters are uppercase, otherwise False.
Join (sub) Inserts a string as a delimiter between all the characters in a sub.
Ljust (width) Returns a left-aligned string and fills the new string with a width of length with a space.
Lower () Converts all uppercase characters in a string to lowercase.
Lstrip () Remove all spaces to the left of the string
Partition (sub) Locate the substring sub, divide the string into a 3-tuple (pre_sub, Sub, fol_sub), and return if the string does not contain a sub (' Original string ', ' ', ')
Replace (old, new[, Count]) Replaces the old substring in the string with the new substring and, if count specifies, does not exceed count times.
RFind (sub[, start[, end]]) Similar to the Find () method, it is just looking from the right.
Rindex (sub[, start[, end]]) Similar to the index () method, but starting from the right.
Rjust (width) Returns a right-aligned string and fills the new string with a width of length with a space.
Rpartition (sub) Similar to the partition () method, it is just looking from the right.
Rstrip () Removes a space at the end of a string.
Split (Sep=none, Maxsplit=-1) The default is a space-delimited slice string without parameters, and if the Maxsplit parameter has a setting, only the Maxsplit substring is separated, returning the list of sub-string concatenation after the slice.
Splitlines ([keepends]) Returns a list containing the rows as elements, separated by ' \ n ', and returns the first Keepends row if the Keepends parameter is specified.
StartsWith (prefix[, start[, end]]) Checks whether the string starts with prefix, returns TRUE, or False. The start and end parameters allow you to specify a range check, optional.
Strip ([chars]) Remove all whitespace from the front and back of the string, the chars parameter can be customized to remove the character, optional.
Swapcase () Flips the case in the string.
Title () Returns a string that is titled (all words are started in uppercase and the remaining letters are lowercase).
Translate (table) The characters in the string are converted according to the table's rules (which can be customized by Str.maketrans (' A ', ' B ').
Upper () Converts all lowercase characters in a string to uppercase.
Zfill (width) Returns a string of length width, the original string is right-aligned, and the front is filled with 0.

String built-in methods in Python

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.