There is no need to use the .replace method.
This can be achieved by escaping the escape character which would print \
#/usr/bin/python3 x = "foo\\$" print(x) #outputs foo\$