Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading