Why when I write back slash in brackets, gives an error?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Alexandr

When i do like this
print(“/”)
I get an error
Parse Error: Invalid escape sequence.
I found a way to solve it
print(“//”) make two slash
But I cannot understand the very reason for this error.

:bust_in_silhouette: Reply From: guppy42

An escape character escapes the next character so that it looses any special meaning.

If you place it before a " that would normally terminate the string it instead becomes part of the string, in the case of print("\") that means you have an unterminated string of ")

Much like you can make the quote mark ( " ) loose its meaning you can also make the escape character it self loose it’s meaning by escaping it - that is why print("\\") works

As a side note; the character \ is a back slash, where as / is a forward slash and they usually carry very different meanings in programming languages - backslash is almost always used as an escape character, and forward slash mark the boundaries of regexes