Replace function for Strings in Python

Does the replace function creates a new string or it updates the old string?(because as it was said that strings in python are immutable,so I think it should create a new string)

Yeah it sends a copy of the string not change the original one.

Everything in Python is an object . You have to understand that Python represents all its data as objects. An object’s mutability is determined by its type. Some of these objects like lists and dictionaries are mutable , meaning you can change their content without changing their identity. Other objects like integers, floats, strings and tuples are objects that can not be changed.

Strings are Immutable

Strings are immutable in Python, which means you cannot change an existing string. The best you can do is create a new string that is a variation on the original.