Reputation: 3
# string containing backslash and double quotes, cannot replace backslash
text = 'Sleep Profile will compare a user\'s trends to what\'s typical for "their" age'
text.replace('\\', '')
'Sleep Profile will compare a user\'s trends to what\'s typical for "their" age'
# string containing backslash without double quotes, can replace backslash
text = 'Sleep Profile will compare a user\'s trends to what\'s typical for their age'
text.replace('\\', '')
'Sleep Profile will compare a user's trends to what's typical for their age'
I don't understand why it can't detect the backslash or how to actually achieve my goal of being able to remove them with the original sentence with double quotes.
Any help is greatly appreciated.
Upvotes: 0
Views: 331
Reputation: 36
That's probably because you're testing it on interactive.
If you notice, on the second example the string is represented by double quotes and not single quotes as the first one.
In order to keep the single quotes and the double quotes, on interactive, it escapes the single quote on console. However, if you log it to a file, you would see the single quote there
Edit: Added image to better understanding
Upvotes: 1