How do I escape backslash and single quote or double quote in Python?

前端 未结 5 1323
甜味超标
甜味超标 2020-12-06 19:57

How do I escape a backslash and a single quote or double quote in Python?

For example:

Long string = \'\'\'some \'long\' string \\\' and \\\" some \'         


        
5条回答
  •  醉酒成梦
    2020-12-06 20:34

    I try this to print a single backslash (Python 3):

    single_backslash_str = r'\ '[0]
    print('single_backslash_str')         #output: \
    print('repr(single_backslash_str)')   #output: '\\'
    

    Hope this will help!

提交回复
热议问题