a.replace('i','m',2) 'Engmneermng performs magic' a.replace('i','m',3) 'Engmneermng performs magmc' a.replace('e','k') 'Enginkkring pkrforms magic' a.replace('E','S') 'Sngineering performs magic' a.replace('n','q',1) 'Eqgineering performs magic' a.replace('n','q',2) 'Eqgiqeering performs magic' KeyboardInterrupt a.replace('n','q',3) 'Eqgiqeeriqg performs magic' l = 'Pop music has great energy' l.replace('e','s',3) 'Pop music has grsat snsrgy' l.replace('P','p') 'pop music has great energy'
#split()
k = 'KK was a great singer'
k.split('a',1) ['KK w', 's a great singer'] k.split('a',2) ['KK w', 's ', ' great singer'] k.split('a',3) ['KK w', 's ', ' gre', 't singer'] k.split(' ') ['KK', 'was', 'a', 'great', 'singer'] k.split('K') ['', '', ' was a great singer'] k.split('K',1) ['', 'K was a great singer'] ['', 'K was a great singer'] ['', 'K was a great singer'] k.split('s',1) ['KK wa', ' a great singer'] k.split('s',2) ['KK wa', ' a great ', 'inger'] k.split('e',2) ['KK was a gr', 'at sing', 'r']
#rsplit()
m= ' Whatsapp is good messaging tool'
m.rsplit('') Traceback (most recent call last): File "<pyshell#33>", line 1, in <module> m.rsplit('') ValueError: empty separator m.rsplit() ['Whatsapp', 'is', 'good', 'messaging', 'tool'] m.rsplit(' ') ['', 'Whatsapp', 'is', 'good', 'messaging', 'tool'] m.rsplit('o',1) [' Whatsapp is good messaging to', 'l'] m.rsplit('o',3) [' Whatsapp is go', 'd messaging t', '', 'l'] m.rsplit('a',2) [' Whats', 'pp is good mess', 'ging tool'] ,rsplit('s',2) SyntaxError: invalid syntax m.rsplit('s',2) [' Whatsapp is good me', '', 'aging tool'] m.split('s',3) [' What', 'app i', ' good me', 'saging tool'] m.rsplit('s',3) [' Whatsapp i', ' good me', '', 'aging tool'] m.rsplit('h',-1) [' W', 'atsapp is good messaging tool'] m.rsplit('h') [' W', 'atsapp is good messaging tool'] m.rsplit('h',-2) [' W', 'atsapp is good messaging tool'] m.rsplit('p',1) [' Whatsap', ' is good messaging tool'] m.rsplit('g',2) [' Whatsapp is good messa', 'in', ' tool']