Today, the problem of resolving the software name and version number from the URL is recorded here, mainly Python string manipulation and common regular expressions.
The string in Python is an immutable sequence, meaning that a defined string cannot be modified in place.
- Python string declaration
' Hello World ' "helloWorld", "Hello World" "" "HelloWorld" ""
The declaration of a python string can be a single or double quotation mark, or it can be a three-quote, single, double-quoted, but cannot be mixed.
If you mix Python's single and double quotes, you need to add the escape character \
" he\ ' s Mom "
- Raw string Suppression escape
We have something to do with the file system, if it's a novice, it might.
MyFile = open ('C:\new\text.dat','w')
But this can be problematic because \ nthe is escaped, so to avoid this, we can use the following two ways:
MyFile = open ('c:\\new\\text.dat','w'= open ( R'C:\new\text.dat','w')
The second way is recommended, because there are no more slashes to confuse.
- Methods used to process strings in real-world projects
STR6 ="goodevening"Printlen (str) STR7= str1 +str2PrintSTR7Print "hi!"* 4#Traversing Strings forChinch "Hello World": PrintCh.upper ()#capitalize a string#indexes and ShardsBCD ="ABCDEFG"[1:4]#BCDEFG ="ABCDEFG"[-3:]#EFGc ="ABCDEFG"[2]#determines whether a string is a number"123". IsDigit ()#True"123.22". IsDigit ()#False#String Formatted outputinfo ="My name is {0} I am {1} years old". Format ("MJ","Wuyi")PrintInfo#String Lookup"Hello World". Find ("Lo")#3"Hello World". Find ("o", 6, 8)#7"Hello World". Find ("Morning")#-1#string Substitution"Hello". replace ("Hi","Ye")#Hello because I can't find Hi"Hello". replace ("H","h")#Hello#Remove SpacesPrintLen"Strip")#Length of 7PrintLen"Strip". Strip ())#Length of 5#determine whether to end with a string beginningPrint "StartEnd". StartsWith ("Start")Print "StartEnd". EndsWith ("End")#string transcodingPrintOrd"a")# thePrintChr (98)#b
Let's just write it up and have time to add it.
Python string manipulation