How to include backslash and quotes in Python strings

前端 未结 4 1056
故里飘歌
故里飘歌 2021-01-27 00:41

I\'ve got an array of special characters that looks something like this.

specialCharList=[\'`\',\'~\',\'!\',\'@\',\'#\',\'$\',\'%\',\'^\',
             \'&\'         


        
4条回答
  •  广开言路
    2021-01-27 01:16

    The backslash \ character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.

    example:

    \\  Backslash (\)    
    \'  Single quote (')     
    \"  Double quote (")
    

    Escape characters are documented in the Python Language Reference Manual. If they are new to you, you will find them disconcerting for a while, but you will gradually grow to appreciate their power.

提交回复
热议问题