Run
# Input string x = "Hello, World! Hello, Universe!" # Substring to be replaced old_substring = "Hello" # Replacement string new_substring = "Hi" # Replace the first occurrence result_string = x.replace(old_substring, new_substring, 1) # Print the result print(f"Original : {x}") print(f"Result : {result_string}")
Output