Run
# Given string x = "/path/to/something/" # Replace forward slash with backward slash result = x.replace('/', '\\') print(result)
Output