Basic Python knowledge: string processing and basic python knowledge
Python string processing
String input:
my_string = raw_input("please input a word:")
String judgment:
(1) determine whether it is a pure letter
my_string.isalpha()
String SEARCH matching:
(1) re
Re Regular Expression Example 1: ^ [\ w _] * $
First, \ w indicates matching any word characters including underscores, which is equivalent to '[A-Za-z0-9 _]'.
Then followed by _.
*: Matches the previous subexpression zero or multiple times. For example, zo * can match "z" and "zoo ". * Is equivalent to {0 ,}.
$: Indicates that the string ends and no other characters are followed.
Therefore, this expression refers to the [\ w _] (any word character includes an underscore, followed by an underscore) as a whole, and appears zero or multiple times!
import remy_string = raw_input("please input a word:")if re.match('^[a-zA-Z]$', my_string):print "it is a word"else:print "it is not a word"
String Conversion:
(1) convert the string to lowercase letters.
my_string = my_string.lower()
(2) connect multiple strings together.
my_string = my_string + "abc"
(3) Part of the string. In this example, the first and last characters are removed and the middle section is truncated.
my_string = my_string[1:len(my_string)-1]
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!