Some important methods of string
Find () returns the leftmost index of the substring location. If no index is found,-1 is returned.
Join () is the inverse method of the split () method, used to add elements to the queue.
SEQ = ['1', '2', '3'] Sep = '/' print Sep. join (SEQ) Sep = '\' print Sep. join (SEQ) running result:
Running result:
1/2/3
1 \ 2 \ 3
Lower (), returns the lower-case character of the string.
Replace (string a, string B) returns the string obtained after all the matches of string a are replaced with B.
Split () to split the string into a sequence.
Strip () removes strings on both sides (excluding internal.
Translate () and replace multiple single characters at the same time.
The following is a testProgram
#-*-coding: UTF-8-*-'''created on 2013-7-7 @ Author: ginsmile ''' from string import maketransmystr = '! This is a simple .!! 'Mystr = mystr. Strip ('! ') # Remove spaces and exclamation points on both sides print mystr # This is a simple. print mystr. lower () # This is a simple. print mystr. capitalize () # This is a simple. print mystr. upper () # This is a simple. SEQ = mystr. split ('') print seq # ['this', 'is ', 'A', 'simple. '] print ''. join (SEQ) # This is a simple. table = maketrans ('cs ', 'kz') print Len (table) #256 print table [97: 123] # abkdefghijklmnopqrztuvwxyz # above, table is successfully written as a conversion table. Print 'this is another Simple. Cut the hair ~~ '. Translate (table) # thiz iz another zimple. Kut the hair ~~