Function Details: replace

Description


Returns a copy with all occurrences of substring old replaced by new.


Extended Description


The replace() method returns a new string where all occurrences of a specified substring are replaced with another specified string. If the 'count' parameter is provided, it replaces only the first 'count' occurrences.


Read More about replace from Python Documentation

Function Signature



Module: builtins

Class: str

Parameters



Parameter List


  • old: str
  • new: str
  • count: int

Return


Returns a new string with specified replacements.


Return Type


str

Output

Explanation

This example demonstrates the basic usage of replace(). It replaces all occurrences of 'hello' with 'hi'.