You need to escape the backslash before the "3" Even if the backslash is in the quotes it will NOT be escaped.
If you're programitically inserting the value in the function, then I suggest performing another .replace and replace the "\" with a "-"

That should convert the string to "21-3-90" and if you need to break it down further, you can replace the "-" to a " " as you originally intended.

akhter@uf8b156e44b21553641ed:~/PycharmProjects/untitled2$ python3.2
Python 3.2.3 (default, Feb 27 2014, 21:31:18) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def process(date):
...     date = date.replace("\\", " ")
...     print(date)
... 
>>> process("21\\3\\90")
21 3 90
>>> process("13\\4\\90")
13 4 90
>>> 

akhter@uf8b156e44b21553641ed:~/PycharmProjects/untitled2$ python2.7
Python 2.7.3 (default, Dec 18 2014, 19:10:20) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def process(date):
...     date = date.replace("\\", " ")
...     print(date)
... 
>>> process("21\\3\\90")
21 3 90
>>> 
akhter@uf8b156e44b21553641ed:~/PycharmProjects/untitled2$ python3.2
Python 3.2.3 (default, Feb 27 2014, 21:31:18) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def process(date):
...     date = date.replace('\\', ' ')
...     print(date)
... 
>>> process("21\\3\\90")
21 3 90
>>> 
Answer from Mo Ali on Stack Overflow
🌐
CodeSpeedy
codespeedy.com › home › replace spaces with backslashes in python
Replace spaces with backslashes in Python - CodeSpeedy
March 23, 2023 - We use the replace() method on the Python string to replace all spaces with backslashes, and it returns a copy of the replaced string. The first argument is the value we want to be replaced, and the second argument is the value that will replace ...
Discussions

how to replace back slash character with empty string in python - Stack Overflow
I want to replace' ... Note that the \ sequence in the string literal in the example becomes an actual backslash followed by a space. When Python scans a string literal and finds an unrecognized escape sequence, it leaves the backslash in the string. More on stackoverflow.com
🌐 stackoverflow.com
python - Replacing everything with a backslash till next white space - Stack Overflow
As part of preprocessing my data, I want to be able to replace anything that comes with a slash till the occurrence of space with empty string. For example, \fs24 need to be replaced with empty or \qc23424 with empty. There could be multiple occurrences of tags with slashes which I want to remove. More on stackoverflow.com
🌐 stackoverflow.com
String replace with backslashes in Python - Stack Overflow
I'm trying to do a simple replacement of " " with "\s" (the literal \s, not some sort of backslash escape). This is what I think should happen: >>> 'asdf hjkl'.replace(' ', '\s') 'asdf\sh... More on stackoverflow.com
🌐 stackoverflow.com
string - python replace single backslash with double backslash - Stack Overflow
How can I put an actual backslash in a string literal (not use it for an escape sequence)? (4 answers) Closed 3 years ago. In python, I am trying to replace a single backslash ("\") with a double backslash("\"). More on stackoverflow.com
🌐 stackoverflow.com
August 21, 2018
🌐
Reddit
reddit.com › r/python › how do you replace a character in a string with a single backslash?
r/Python on Reddit: How do you replace a character in a string with a single backslash?
March 16, 2015 -

The goal: 'apple' -> 'app\e'

This doesn't work:

>>> "apple".replace('l', '\\')
'app\\e'

This also doesn't work:

>>> "apple".replace('l', '\')
  File "<stdin>", line 1
    "apple".replace('l', '\')
                             ^
SyntaxError: EOL while scanning string literal
🌐
Tutorial Gateway
tutorialgateway.org › python-string-replace
Python String Replace
March 25, 2025 - This program allows the user to enter the text, words to change, and the new text to substitute. Next, we used this Python string replace function to alter the old with the new. We are using the string replace function to change Backslash with forward-slash.
Find elsewhere
🌐
Python Forum
python-forum.io › thread-37781.html
change backslash into slash in a path
July 21, 2022 - Hi Typically in a Windows path, I want to change the special 'backslash' character to 'slash' one. I was thinking re.sub substitutes all occurences but whatever I've tested so far, it fails (same result using replace()): what I'm missing? Path = 'D...
🌐
McNeel Forum
discourse.mcneel.com › scripting
Python - replace backslash in string - rs.documentpath() - Scripting - McNeel Forum
June 16, 2015 - Trying to replace the backslash character in a string obtained with the rs.documentpath() method. The string replace function will not work since the backslash is an escape character. Any way to change my string into a r…
🌐
Quora
quora.com › How-do-you-change-a-double-backslash-to-a-single-back-slash-in-Python
How to change a double backslash to a single back slash in Python - Quora
Answer: This is an interesting one. A few important notes before my answer code: * To put a backslash in a string literal, type two backslashes. The first one indicates the start of an escape sequence; the second one indicates you want the escape sequence to produce a backslash. (If you wanted ...
🌐
GitHub
github.com › PyImageSearch › imutils › issues › 61
paths.py - replacing space with slash+space · Issue #61 · PyImageSearch/imutils
March 27, 2018 - First of all, thanks for the library. Very useful! Second, I wanted to ask you why do you replace space with slash+space in paths.py? Is this a bug or something you've done on purpose? imagePath = os.path.join(rootDir, filename).replace(" ", "\\ ") PS: I'm using Windows and Python3.
Author   PyImageSearch
🌐
Python documentation
docs.python.org › 3 › reference › lexical_analysis.html
2. Lexical analysis — Python 3.14.6 documentation
Tabs are replaced (from left to right) by one to eight spaces such that the total number of characters up to and including the replacement is a multiple of eight (this is intended to be the same rule as used by Unix). The total number of spaces preceding the first non-blank character then determines the line’s indentation. Indentation cannot be split over multiple physical lines using backslashes; the whitespace up to the first backslash determines the indentation.
🌐
Codeigo
codeigo.com › home › replace forward slash with backslash in python
Replace Forward Slash With Backslash in Python - Codeigo
April 19, 2023 - A forward-slash (/) in a Python string can be replaced by a backslash (\) using the String replace() function, translate() method, or regular expression(re.sub()). ... To get more details about those concepts, continue reading on. There is more to learn. First of all, let’s discuss backslash.
🌐
py4u
py4u.org › blog › python-regex-to-replace-double-backslash-with-single-backslash
How to Replace Double Backslash with Single Backslash in Python Using Regex: Fixing Common Escape Errors
User input (e.g., from input() or CLI arguments) may contain unescaped backslashes, which Python converts to double backslashes when stored. To replace double backslashes (\\) with single backslashes (\), regex is ideal because it can precisely target literal backslashes.
🌐
py4u
py4u.org › blog › python-replace-backslashes-to-slashes
Python: Replace Backslashes with Slashes – How to Escape Backslashes and Convert XML Strings to Raw Strings
Use str.replace("\\", "/") to convert backslashes to forward slashes. Raw strings (r"...") simplify working with literal backslashes. Escape backslashes with \\ in normal strings to avoid syntax errors. By following these practices, you’ll ensure consistent, error-free string manipulation in Python.
🌐
Quora
quora.com › How-do-you-backslash-a-string-in-Python
How to backslash a string in Python - Quora
For usage beyond displaying simple ... - the python standard library has a number of different functions for instance : ... Strictly speaking the html.escape doesn’t mark special characters with backslashes. The html standard is to convert literal characters to a ascii code or a special names and then preceeding the code by a ‘&’ character and appending the code with a semicolon ‘;’ - for instance a space becomes &#x20; ...