Why is "HELLO\\2" not equal to """HELLO\2""" in Python 3.8.2

I’m trying to figure out why Python 3.8.2 considers this is true

"HELLO\\WORLD" == """HELLO\WORLD"""

But this is false

"HELLO\\2" == """HELLO\2"""

Why is \2 not interpreted the same in both sides of the string ?

>Solution :

\2 is an octal escape (\x02) while \\2 is an escaped \, followed by the numeral 2. The W doesn’t have a valid escape so "\W" == "\\W"

Leave a Reply