Search code examples
pythonstringvariablesquote

How to use triple quotes?


some variables are being printed wrong.

    gv_sixTries = '''
___________.._______ 
| .__________))______|
| | / /      ||
| |/ /       ||
| | /        ||.-''.
| |/         |/  _  \
| |          ||  `/,|
| |          (\\`_.'
| |         .-`--'.
| |        /Y . . Y\
| |       // |   | \\
| |      //  | . |  \\
| |     ')   |   |   (`
| |          ||'||
| |          || ||
| |          || ||
| |          || ||
| |         / | | \
| |         `-' `-'      
| |                      
| |                      
: :                        
. .                      
'''

the variable is being printed like that: image OS: Windows 10

interpreter: Python IDLE 3.7.2


Solution

  • Prefix an r to your string

    gv_sixTries = r'''
        ___________.._______ 
        | .__________))______|
        | | / /      ||
        | |/ /       ||
        | | /        ||.-''.
        | |/         |/  _  \
        | |          ||  `/,|
        | |          (\\`_.'
        | |         .-`--'.
        | |        /Y . . Y\
        | |       // |   | \\
        | |      //  | . |  \\
        | |     ')   |   |   (`
        | |          ||'||
        | |          || ||
        | |          || ||
        | |          || ||
        | |         / | | \
        | |         `-' `-'      
        | |                      
        | |                      
        : :                        
        . .                      
        '''
    

    This tells python to use the string a raw literal, not using backslashes as escape characters