'Assign sequence of symbols into a variable/string in Python
this sequence of symbols is required as a password in an app:
9h/#13/'!O!Nr},w_T0 6!ws%N\c^i,4"
How can store this to a variable/string?
Solution 1:[1]
One easy way to store those characters in a string is to use Python's triple-quotes.
s = '''9h/#13/'!O!Nr},w_T0 6!ws%N\c^i,4"'''
If your sequence did not end with a double-quote, triple double-quotes could also have been used rather than the triple single-quotes above. The triple-quote way of showing a string is designed for tough cases like yours, with almost any combination of text characters allowed in the string. Executing the command print(s)
gives the output that you want:
9h/#13/'!O!Nr},w_T0 6!ws%N\c^i,4"
Solution 2:[2]
Just declare a string as usual, and escape the special characters '
and "
with \
. The escape makes it act like a string literal, rather than a special character.
str = '9h/#13/\'!O!Nr},w_T0 6!ws%N\c^i,4\"'
Output is
'9h/#13/\'!O!Nr},w_T0 6!ws%N\\c^i,4"'
Solution 3:[3]
Import strings
Strings = string.punctuation
Use this and thank me later
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Rory Daulton |
Solution 2 | Katarina |
Solution 3 | Suraj Rao |