0
>>> normal="The\n\t\n quick silver fox ran over lazy dog's"
>>> normal
"The\n\t\n quick silver fox ran over lazy dog's" # 1
>>> json.dumps(normal)
'"The\\n\\t\\n quick silver fox ran over lazy dog\'s"'
>>> r"The\n\t\n quick silver fox ran over lazy dog's"
"The\\n\\t\\n quick silver fox ran over lazy dog's"
>>> r"{}".format(normal)
"The\n\t\n quick silver fox ran over lazy dog's"
>>> rf"{normal}"
"The\n\t\n quick silver fox ran over lazy dog's"

How can I convert normal string (#1) to raw string (#2) using String Formatting or F-stings

N N K Teja
  • 197
  • 1
  • 7
  • If you have opportunity to use json module - `json.dumps(normal)` – Olvin Roght Jun 10 '20 at 17:06
  • 3
    Does this answer your question? [Convert regular Python string to raw string](https://stackoverflow.com/questions/4415259/convert-regular-python-string-to-raw-string) – sushanth Jun 10 '20 at 17:08
  • Be sure to see [this answer](https://stackoverflow.com/a/4415585/355230) to the linked question. – martineau Jun 10 '20 at 17:12
  • `>>> json.dumps(normal) '"The\\n"'` which is not equivalent to required output `'The\\n'` (# 2) – N N K Teja Jun 10 '20 at 17:37
  • `>>> rf"{normal}" 'The\n' ` [Convert regular Python string to raw string](https://stackoverflow.com/questions/4415259/convert-regular-python-string-to-raw-string) this question does not answer my question. – N N K Teja Jun 10 '20 at 17:41

0 Answers0