Article From:
v=test.lstrip("bcabc")#Find the maximum match and remove the specified string
print("1.lstripUsage 3 to find the most matches and remove the specified characters","\n",v)
test1="Silly ABC"
test2="Who is 123?"
test3="You are all fools, abcefgh321"
a=str.maketrans(test1,test2)  #This STR does not understand why to write str
b=test3.translate(a) #maketrans Make the corresponding relationship with translate first, and then replace the new statement with the new corresponding relationship.
print("2.1:maketrans Make the correspondence by law, translate and replace:","\n",b)
test4="Life is like a play, it's all about acting."
c=str.maketrans("Drama is like life","You are an idiot")# Making Transformational Relationships with Maketrans
print("2.2:First confirm the statement to be converted, then confirm the transformation relationship, and finally use trasnlate to generate the final conversion statement:","\n",d)
e=test.partition("x")# Divide the above statement into three parts, then use X to find the first X and do isolated segmentation. This should be left segmentation.
f=test.rpartition("j") #The statement is split right, and if it is split into the first word, the output is empty.
print("3.partitionThe function is to divide into three parts, and the rpartition is the same:","\n",e,"\n",f)
g=test.split("s",2)#The maximum number of times is 2. Note that s has been removed when segmentation.
print("4.split And rsplit for the specified number of times of partitioning:","\n",g,"\n",h)
i=test.splitlines()#You can only divide it by line break \ n, and fill in True and False in the blanks (if not, it means false) whether to keep line breaks or not.
print("5.splitlines Segmentation based on line breaks:","\n",i,"\n",j)
k=test.startswith("a")#Specifies the beginning of a string
l=test.endswith("j")#Specifies the end of the string
print("6.startswithAnd endswith usage to determine whether a specified string begins or ends:",k,l)
m=test1.swapcase()#toggle case
print("7.Case-to-case swapcase:","\n",m)


Leave a Reply

Your email address will not be published. Required fields are marked *