Python String replace() method

The string.replace() method in Python returns a copy of the string with all occurrences of substring old replaced by new.

Syntax

Parameter

old: This parameter represents a substring you want to replace.

new: This parameter represents a substring which would replace the old substring.

count(optional): It signifies the number of times you want to replace the old substring with the new substring.

Return

This method returns a copy of the string where all occurrences of a substring is replaced with another substring. 

Example 1

Output

Example 2

Output

Pin It on Pinterest

Share This