Python--7 built-in methods for various exotic flowers

Source: Internet
Author: User

Python does not have a character type that is a single character or string length of 1

Once a string is defined, it cannot be modified

>>> str1 = ' I love junjie.com '
>>> Str1[:6]
' I love '

>>> str1
' I Love junjie.com '
>>> str1[5] substring
E

>>> Str1[:6] + ' inserted string ' + str1[6:]
' I love to insert string junjie.com '

List tuple strings are sequences

Methods and comments for strings

Capitalize () Change all characters of the entire string to uppercase
Casefold () Change all characters of the entire string to lowercase
Center (width) Center the string and fill it with a space? A new string of degrees 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 () If the string has at least one character and all characters are letters or numbers return True, no returns FALSE.
Isalpha () If the string has at least one character and all characters are alphabetic, returns True, no returns FALSE.
Isdecimal () Returns True if the string contains only 10 digits, and no returns FALSE.
IsDigit () Returns True if the string contains only a number, otherwise False.
Islower () If the string contains at least one case-sensitive character, and the characters are lowercase, returns True, and no returns FALSE.
IsNumeric () Returns True if the string contains only numeric characters, otherwise false is returned.
Isspace () Returns True if the string contains only spaces, and no returns FALSE.
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) Return a left pair? string, and use a space to populate it with? A new string with a width of degrees.
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-dollar (pre_sub, sub,fol_sub) If the string does not contain a sub-return (' original string ', ' ', ')
Replace (old, new[, Count]) Replaces the old substring in the string with the new substring if count specifies that the substitution 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) Return a right pair? string, and use a space to populate it with? A new string with a width of degrees.
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) Return? The width of the string, the original string right, the front is filled with 0.

Python--7 built-in methods for various exotic flowers

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.