human
Give me a Python code to replace all occurences of old with new in a string.
assistant
Here is a Python code to replace all occurences of old with new in a string

import re

def replace_all(old, new, string):
        """
        Replaces all occurences of old with new in a string.
        """
        return string.replace(old, new)

# Enter the string
string = "This is a string"

# Calling the function
print((replace_all("a", "b", string)))

#Example Output
# This is b string

#Remember to inspect code for bugs.