Mega Code Archive

 
Categories / Python Tutorial / String
 

Replacing a substring

string1 = "One, one, one, one, one, one" print "Original:", string1 print 'Replaced "one" with "two":', \    string1.replace( "one", "two" ) print "Replaced 3 maximum:", string1.replace( "one", "two", 3 )