How to correctly write a raw multiline string in Python?

后端 未结 2 1054
别跟我提以往
别跟我提以往 2020-12-19 11:51
  1. I know that you can create a multi-line string a few ways:

Triple Quotes

\'\'\'
This is a 
multi-line
string.
\'\'\'


        
相关标签:
2条回答
  • 2020-12-19 12:27

    You'd need a r prefix on each string literal

    >>> (r'on\e'
         r'\tw\o')
    'on\\e\\tw\\o'
    

    Otherwise the first portion is interpreted as a raw string literal, but the next line of string is not, so the '\t' is interpreted as a tab character.

    0 讨论(0)
  • 2020-12-19 12:32

    I think you might also need to make the second line a raw string as well by prefixing it with the r as you did in r'on\e'

    0 讨论(0)
提交回复
热议问题