S = 'xxxxSPAMxxxxSPAMxxxx' where = S.find('SPAM') # search for position print where S = S[:where] + 'EGGS' + S[(where+4):] print S