#!/usr/bin/python#This section learns about string manipulation in Python#strings exist as sequences in Python, and other sequences have lists and tuples#1. Operation of the sequenceS='Spam' #defines a sequencePrint(Len (S))#gets the length of the sequencePrint(S[0])#gets the first character of a stringPrint(S[1])#gets the second character of a string#Conclusion: The string in Python is indexed starting at 0#python variables do not need to be declared in advance#when a variable is assigned a value, it is created and may be assigned to any type of object#variables must be assigned before they are used#Reverse Index stringPrint(S[-1])#the last character in SPrint(S[-2])#The second-to-last character in SPrint(S[len (S)-1])#get the last character in S from the number of days you go#2. Shard operations, which can intercept part of a stringS='Spam'Print(S[1:3])#s in the index from 1 to 2 of the substring, not including 3, that is, left closed right open intervalPrint(S[1:50])#the following values can be very largePrint(S[-50:50])#estimated from 0~len#in one Shard, the left boundary defaults to 0, and the right boundary defaults to the length of the Shard sequencePrint(s[1:])Print(S[0:3])Print(S[:-1])#This is also the other characters to take apart the last one, remember that it is the right openPrint(s[:])#the whole string, remember not to write is 0~len#3. Strings can be connected with a plus + +Print(S +'XYZ')#that is, the operating system written by Python can usually automatically adapt to different types of objects#4. immutability#with the final meaning in Java, after you have modified the string,#get another string, not a modification based on that.#5. What are the methods of the string object#Find Lookup substring#Replace replacement#Split Split#Upper into uppercase#Isalpha judge is not the letter#Rstrip Remove the blank character on the right#format is also formatted#formatting operations, associating printf#6. Other ways to manipulate strings#Len Gets the length of the string#Ord gets the ASCII value corresponding to the character#It doesn't mean the end of the string.Print(Len ('a\0b\0c'))#The result is 5 .#Python supports single quotes, double quotes, and three quotation marks#pattern matching, that's the regular expression.ImportRe#Introducing Regular ExpressionMatch = Re.match ('hello* (. *) World','Hello Python World')Print(Match.group (1) ) Match.group ()#get all of the matching strings
Python Learning (iv) String learning