Search code examples
pythonstringsymbols

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

  • 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"