- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to replace \ with in Python?
There are two ways to go about replacing \ with \ or unescaping backslash escaped strings in Python. First is using literal_eval to evaluate the string. Note that in this method you need to surround the string in another layer of quotes. For example:
>>> import ast >>> a = '"Hello,\\nworld"' >>> print ast.literal_eval(a) Hello, world
Another way is to use the decode('string_escape') method from the string class. For example,
>>> print "Hello,\\nworld".decode('string_escape') Hello, world
- How i can replace number with string using Python?
- How to replace values in a Python dictionary?
- How to Search and Replace text in Python?
- Program to replace all digits with characters using Python
- How to replace all occurrences of a string with another string in Python?
- Python Program to replace a word with asterisks in a sentence
- How to replace values of a Python dictionary?
- How to replace rows in a MySQL table with conditions?
- How to replace 0 with NA in an R matrix?
- Replace NaN with zero and infinity with large finite numbers in Python
- How can MySQL find and replace the data with REPLACE() function to UPDATE the table?
- Search and Replace in Python
- How to replace multiple spaces with a single space in C#?