Python String replace() MethodReturn a copy of the string with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced. Syntax:Parametersold: Here this parameter is used for old string which will be replaced. new: Here this parameter is used for new string which will replace the old string. count: The count parameter is used to describe the number of times to process the replace. ReturnIt returns string Let's see some examples of replace() method to understand it's functionality. Example 1Output: The Old String before performing the replace method is: Java is a programming language The new String after performing the replace method is: C is a programming language Example 2Output: Old String: The Old String before performing the replace method is: Java C C# Java Php Python Java The new String after performing the replace method is: C# C C# C# Php Python C# The Old String before performing the replace method is: Java C C# Java Php Python Java The new String after performing the replace method is: C# C C# Java Php Python Java Example 3Output: Tomato is also a fruit Next TopicPython Strings |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India