Can't do ASCII with 'u' character in python

Question:

I’m trying to do an ascii image in python but gives me this error

File "main.py", line 1
    teste = print('''
                  ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 375-376: truncated UXXXXXXXX escape

And I think it’s because of the U character, why that happened, is any way to solve this?
ASCII image

Asked By: gabrielleAmbrosio

||

Answers:

You’ve got U in your string, which is being interpreted as the beginning of a Unicode ordinal escape (it expects it to be followed by 8 hex characters representing a single Unicode ordinal).

You could double the escape, making it \U, but that would make it harder to see the image in the code itself. The simplest approach is to make it a raw string that ignores all escapes save escapes applied to the quote character, by putting an r immediately before the literal:

teste = print(r'''

Note the r immediately after the (, before the '''.

Answered By: ShadowRanger
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.