Syntax :

str.replace(old, new[, max])

 

Note :

  • str: variable string
  • old: string lama yang ingin dirubah
  • new: string baru yang akan menggantikan string lama
  • max: maximal string yang akan dirubah

 

Contoh Penggunaan :

str = “this is string example….wow!!! this is really string”;
print str.replace(“is”, “was”);
print str.replace(“is”, “was”, 3);

 

Hasil :

thwas was string example….wow!!! thwas was really string
thwas was string example….wow!!! thwas is really string

 

Sumber : http://www.tutorialspoint.com/python/string_replace.htm