I\'ve got an array of special characters that looks something like this.
specialCharList=[\'`\',\'~\',\'!\',\'@\',\'#\',\'$\',\'%\',\'^\',
\'&\'
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.
You can use single, double ot triple quotes for delimiting strings.
So "'"
, '"'
are ways to have a quote character in your string.
The readability of your list could be greatly improved by putting your special characters in a string:
>>> SCL = "`~!@#$%^&*()_-+=|{}[],;:'.><?/" + '"\\'
>>> specialCharacters = list(SCL)
We're combining two strings, one delimited by "
and where we put '
, the second delimited by '
and where we put "
and \\
(that we have to escape, so we have to put '\\'
).
There is an inbuilt module called string
in Python. This can be used.
>>>
>>> import string
>>> string.punctuation
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
>>>
>>> list(string.punctuation)
['!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~']
>>>