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