Python Learning Basics of string processing understanding

Source: Internet
Author: User
python string processing
String input:

my_string = raw_input ("Please input a word:")


String judgment:
(1) Judgment is not pure letter

My_string.isalpha ()


String Search matches:
(1) Re
Re-regular Expression instance one: ^[\w_]*$
The first \w is to match any word character that includes an underscore, equivalent to ' [a-za-z0-9_] '.
And then followed a _.
Look again * Number: matches the preceding subexpression 0 or more times. For example, zo* can match "z" and "Zoo". * Equivalent to {0,}.
The last is $: Indicates the end of the string, followed by no more characters.
So, the meaning of this expression is to see this [\w_] (any word character including underscores, and then underlined) as a whole, appearing 0 or more times!

Import remy_string = raw_input ("Please input a word:") if Re.match (' ^[a-za-z]$ ', my_string):p rint "It is a word" else:print "It's not a word"


String Transformations:
(1) Convert the string to a lowercase letter.

my_string = My_string.lower ()


(2) concatenate multiple strings together.

my_string = my_string + "abc"


(3) Intercept part of the string. This example removes the first and last characters and intercepts the middle segment.

my_string = My_string[1:len (my_string)-1]


Thank you for reading, hope to help everyone, thank you for the support of this site

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.