Python raw strings and trailing backslash

前端 未结 4 1729
刺人心
刺人心 2020-12-03 06:49

I ran across something once upon a time and wondered if it was a Python \"bug\" or at least a misfeature. I\'m curious if anyone knows of any justifications for this behavi

4条回答
  •  攒了一身酷
    2020-12-03 07:40

    Thoughts on why 'raw' strings are 'raw, except for backslash-quote'? I mean, if I wanted to embed a single quote in there I'd just use double quotes around the string, and vice versa.

    But that would then raise the question as to why raw strings are 'raw, except for embedded quotes?'

    You have to have some escape mechanism, otherwise you can never use the outer quote characters inside the string at all. And then you need an escape mechanism for the escape mechanism.

提交回复
热议问题