How to correctly write a raw multiline string in Python?

后端 未结 2 1074
别跟我提以往
别跟我提以往 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.

提交回复
热议问题