String input:
my_string = Raw_input ("pleaseinput 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= raw_input ("Pleaseinput a word:")if re.match ( ' ^[a-za-z]$ ' , my_string):print"it is a word"else: Print " It is not a word "
String Transformations:
(1) Convert the string to a lowercase letter.
my_string = My_string.lower ()
(2) concatenate multiple strings together.
" 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]
Python string processing