Python starts with small white-string manipulation (not modifiable)

Source: Internet
Author: User

String manipulation cannot be modified
1Say ="Hello, world,66."2 Print(Say.capitalize ())#output Hello, world,66 first letter capitalization3 4 Print(Say.casefold ())#output Hello, world,66 uppercase all lowercase5 6 Print(Say.center (30,"-"))#output-------Hello, world,66-------returns the center of the original string and fills the new string with "character" to the width of length7 8 Print(Say.count ("o"))#Output 2 Print out the number of occurrences of "character"9 Ten Print(Say.encode ())#output B ' Hello, world\xef\xbc\x8c66 ' encodes string in the encoded format specified by encoding, One  A Print(Say.endswith ("6"))#output True to determine whether the string ends with the specified suffix, -  - Print(Say.find ("Wo", 0,-1))#Output 8 detects if the string contains substrings of STR, the                                                                          #If you specify the Beg (start) and end (end) ranges, the check is included in the -                                                                          #returns 1 if the containing substring returns the starting index value within the specified range.  - Print(Say.index ("Wo", 0,-1))#Output 8 is the same as the Find () method, except that STR does not report an exception if it is not in a string.  -  +str ="+" -Say2 = ["AA","BB","CC"] + Print(Str.join (Say2))#The output AA+BB+CC generates a new string from the elements in the sequence with the specified character connection.  A  atSTR2 ="a+b+c+d+e+f" - Print(Str2.partition ("+"))#The output (' A ', ' + ', ' b+c+d+e+f ') is the first substring to the left of the delimiter, the second is the delimiter itself, and the third is the substring to the right of the delimiter . -  - Print(Str2.replace ("+","-", 3))#The output a-b-c-d+e+f replaces the old string in the string with the new one, and if you specify the third parameter max, the replacement does not exceed Max times.  -  - Print(Str2.split ("+", 2))#The output [' A ', ' B ', ' c+d+e+f '] slices the string by specifying a delimiter, and if the parameter num has a specified value, only the NUM substring is delimited.  in  - Print(Str2.strip ("A"))#the output +b+c+d+e+f is used to remove the character specified by the string Kinsoku (the default is a space).  to  +Intab ="ABCDE" -Outtab ="12345" theTrantab =Str2.maketrans (Intab, Outtab) * Print(Str2.translate (Trantab))#output 1+2+3+4+5+f A character that converts a string based on the table given by the parameter table (contains 256 characters),

Python starts with small white-string manipulation (not modifiable)

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.