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

前端 未结 5 1316
甜味超标
甜味超标 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:41

    is this what you want?

    import re
    Long_string = "some long string \' and \" some escaped strings"
    value_to_change = re.compile( "'|\"" )
    modified = re.sub(value_to_change , 'thevalue' , Long_string )
    print modified 
    

提交回复
热议问题