Python string built-in functions

Source: Internet
Author: User
Tags string methods

Python string built-in functions
String methods are slowly added from python1.6 to 2.0-they are also added to Jython.
These methods implement most of the methods of the string module, as shown in the following table, which lists the currently supported methods for string literals, all of which contain support for unicode, and some are even specifically for Unicode.
Method description

1String.capitalize ()#capitalize the first character of a string2String.center (width)#returns the center of the original string and fills the new string with a space of length width3String.count (str, beg=0, end=Len (string))4 #returns the number of occurrences of STR in a string, if beg or end specifies that the number of STR occurrences in the specified range is returned5String.decode (encoding='UTF-8', errors='Strict')6 #decodes a string in the encoded format specified by encoding, If an error defaults to a ValueError exception unless errors specifies ' ignore ' or ' replace '7String.encode (encoding='UTF-8', errors='Strict')8 #encodes a string in the encoding format specified by encoding, If an error defaults to a ValueError exception unless errors specifies ' ignore ' or ' replace '9String.endswith (obj, beg=0, end=Len (string))Ten #checks whether the string ends with obj, or returns False if beg or end specifies whether to end with obj in the specified range, or True if it is. oneString.expandtabs (tabsize=8) a #turns the tab symbol in string strings to a space, and the default number of spaces Tabsize is 8. -String.find (str, beg=0, end=Len (string)) - #detects if STR is contained in a string, and if beg and end specify a range, the check is contained within the specified range, and returns 1 if the index value is returned . theString.index (str, beg=0, end=Len (string)) - #just like the Find () method, only if STR does not report an exception in String. - String.isalnum () - #returns True If the string has at least one character and all characters are letters or numbers, otherwise False + String.isalpha () - #returns True If the string has at least one character and all characters are letters, otherwise False +String.isdecimal ()#returns True if the string contains only a decimal number, otherwise False. aString.isdigit ()#returns True if the string contains only a number, otherwise False. at String.islower () - #returns True If the string contains at least one case-sensitive character, and all of these (case-sensitive) characters are lowercase, otherwise False -String.isnumeric ()#returns True if the string contains only numeric characters, otherwise False -String.isspace ()#returns True if the string contains only spaces, otherwise False is Returned. -String.istitle ()#returns True If string is heading (see title ()), otherwise False - String.isupper () in #returns True if the string contains at least one case-sensitive character, and all of these (case-sensitive) characters are uppercase, otherwise False - String.Join (seq) to #Merges (concatenates) Merges all the elements in the SEQ (the string Representation) into a new string as a string delimiter +String.ljust (width)#returns the left alignment of an original string and fills the new string with the width of length with a space -String.Lower ()#converts all uppercase characters in a string to Lowercase. theString.lstrip ()#truncate the left space of a string * String.maketrans (intab, outtab]) $ #the Maketrans () method is used to create a conversion table of character mappings, for a simple invocation of two parameters, the first argument is a string that represents the character that needs to be converted, and the second argument is the target of the string representation of the Transformation. Panax NotoginsengMax (str)#returns the large letter of the string str.  -Min (str)#returns the small letter of the string str.  the string.partition (str) + #a bit like the combination of Find () and split (), starting with the first position in str, the string is divided into a 3-element tuple (string_pre_str,str,string_post_str), if s Tring does not contain str while string_pre_str = = String. aString.Replace (str1, str2, num=String.count (str1)) the #Replace the str1 in string with the str2, if NUM is specified, the replacement is no more than Num times. +String.rfind (str, Beg=0,end=len (string))#similar to the Find () function, it is just looking from the right. -String.rindex (str, Beg=0,end=len (string))#similar to index (), but starting from the Right. $String.rjust (width)#returns the right alignment of the original string and fills the new string with the width of the length with a space $String.rpartition (str)#similar to the partition () function, It is just looking from the right. -String.rstrip ()#removes a space at the end of a string string. -String.Split (str="", num=String.count (str)) the #Slice string with a delimiter of str, if NUM has a specified value, only the num substring is delimited -String.splitlines (num=string.count ('\ n'))Wuyi #Returns a list that contains rows as elements, separated by rows, and if NUM specifies that only num rows are Sliced. theString.startswith (obj, beg=0,end=Len (string)) - #checks whether the string starts with obj, returns True, or False. If beg and end specify a value, the check is within the specified Range. wuString.strip ([obj])#Execute Lstrip () and Rstrip () on string -String.swapcase ()#Flip the case in a string about String.title () $ #A string that returns "header", meaning that all words start with uppercase and the remaining letters are lowercase (see istitle ()) -String.translate (str,del="") - #converts a string character to a table (containing 256 characters) given by str, and the character to be filtered out into the del parameter -String.upper ()#Convert lowercase letters in string to uppercase aString.zfill (width)#returns a string of length width, the original string is right-aligned, and the front padding is 0 +String.isdecimal ()#the Isdecimal () Method checks whether a string contains only decimal Characters. This method exists only in Unicode Objects. 
View Cod

Python string built-in functions

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.