
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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
- Related Articles
- How to replace all occurrences of a string with another string in Python?
- 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?
- How to Replace null with “-” JavaScript
- Program to replace all digits with characters using Python
- Python Program to replace a word with asterisks in a sentence
- How to replace “and” in a string with “&” in R?
- How to replace values of a Python dictionary?
- Python Program to Replace all Occurrences of ‘a’ with $ in a String
- How to replace leading zero with spaces - JavaScript
- How to replace line breaks with using JavaScript?
- 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

Advertisements