How to include backslash and quotes in Python strings

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

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

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


        
4条回答
  •  失恋的感觉
    2021-01-27 01:41

    There is an inbuilt module called string in Python. This can be used.

    >>>
    >>> import string
    >>> string.punctuation
    '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
    >>>
    >>> list(string.punctuation)
    ['!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~']
    >>>
    

提交回复
热议问题