How to properly escape single and double quotes

后端 未结 3 1696
再見小時候
再見小時候 2021-01-13 00:01

I have a lxml etree HTMLParser object that I\'m trying to build xpaths with to assert xpaths, attributes of the xpath and text of that tag. I ran into a problem when the te

3条回答
  •  深忆病人
    2021-01-13 00:32

    there are more options to choose from, especially the """ and ''' might be what you want.

    s = "a string with a single ' quote"
    s = 'a string with a double " quote'
    s = """a string with a single ' and a double " quote"""
    s = '''another string with those " quotes '.'''
    s = r"raw strings let \ be \"
    s = r'''and can be added \ to " any ' of """ those things'''
    s = """The three-quote-forms
           may contain
           newlines."""
    

提交回复
热议问题