0

In Python, you can define a literal string as a raw string. Surfing on internet, I read that it is equivalent to repr(). More exactly, I tested that:

r"mystring" == repr("mystring")[1:-1]

Is this always true?

Marco Sulla
  • 15,299
  • 14
  • 65
  • 100
  • 2
    No its not, for example `r"\u9000mystring" == repr("\u9000mystring")[1:-1]` evaluates to `False` – adjan Sep 04 '19 at 15:30
  • So I suppose the correct way to convert a raw string to an escaped string is [this one](https://stackoverflow.com/questions/24242433/how-to-convert-a-raw-string-into-a-normal-string) – Marco Sulla Sep 04 '19 at 15:43
  • There isn't such a thing as a "raw string", there are only raw string **literals**. The "conversion" you speak of is *interpreting the text* by replacing some text sequences with other text sequences. You cannot unambiguously "convert to an escaped string" because there are multiple possible "escaped" versions of any given input. – Karl Knechtel Aug 08 '22 at 02:27

0 Answers0