string manipulation of Python

Source: Internet
Author: User

String Manipulation <

  A number, a string, a tuple is an immutable type, that is, the result of the operation is the return value, the source string does not change

mystr = "Hello world! Everybody "

Mystr.find ("Eve") gets the result 13, which is the substring at the beginning of the main string, looking from left to right.

Mystr.rfind ("Eve") looks from right to left.

Find (), RFind (), found to return subscript, no return-1 found. Index () did not find the return exception.

------------------------------------------------------------------------------------------------------

COUNT () returns the number of occurrences of the substring.

Mystr.count (substr, start, end) MyStr the entire string by default.

Mystr.replace (STR1, STR2, num) replaces str1 with STR2, and Num represents the number of replacements.

------------------------------------------------------------------------------------------------------

Split (str, maxsize) cuts a string based on STR and can specify the number of times. The default is to remove the space \ t \ n and other escape characters.

Cuts a string into a tuple.

------------------------------------------------------------------------------------------------------

Title () can capitalize each word in the first letter

Capitalize () capitalize the first letter of the initial word

-----------------------------------------------------------------------------------------------------

EndsWith (obj) can check if the suffix of the file name is obj, which returns true, otherwise false.

StartsWith (obj) checks whether to start with obj.

-----------------------------------------------------------------------------------------------------

Lower () changes the character of the string to lowercase.

Upper () capitalizes the character of the string.

The text that can be used to detect user input.

------------------------------------------------------------------------------------------------------

Center (width) centered, ljust (width) on the left, Rjust (width) on the right, the rest filled with spaces, the total length is width.

Lstrip () Removes the left white space character, Rstrip () removes the right white space character, and strip () deletes both whitespace characters.

Partition (str) divides a string into three parts based on Str.

The Splitlines () is cut according to \ n-NewLine.

------------------------------------------------------------------------------------------------------

Isalpha () judgment is not a pure character.

IsDigit () judgment is not a pure number.

Isalnum () Determines whether numbers are composed of characters.

Isspace () is not only contains spaces.

------------------------------------------------------------------------------------------------------

str = ' = '

MyStr = [' aaa ', ' BBB ', ' CCC ']

Str.join (MYSTR)

Get the result ' aaa=bbb=c ', that is, using STR to concatenate into a string. List composition string

>

  

  

  

  

  

string manipulation of 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.