Skip to the content.

Fall 2024 - P1

3.4 String Operations

3.4 Team Teach String Operations

Replacing Substrings

  • Can replace different parts of a string with something else
  • .replace() in Python and JS
print("Hello Brawler".replace("Brawler", "Mihir"))
Hello Mihir
%%js
console.log("Hello Brawler".replace("Brawler", "Mihir"));
<IPython.core.display.Javascript object>
  • Use Case: Useful for replacing specific parts of text without having to re initiate the whole thing again