Quoting backslashes in Python string literals

前端 未结 4 631
独厮守ぢ
独厮守ぢ 2020-11-22 16:21

I have a string that contains both double-quotes and backslashes that I want to set to a variable in Python. However, whenever I try to set it, the quotes or slashes are eit

4条回答
  •  粉色の甜心
    2020-11-22 17:07

    Another way to end a string with a backslash is to end the string with a backslash followed by a space, and then call the .strip() function on the string.

    I was trying to concatenate two string variables and have them separated by a backslash, so i used the following:

    newString = string1 + "\ ".strip() + string2
    

提交回复
热议问题