Search⌘ K
AI Features

Strings and the Backslashes

Explore how Python handles backslashes in regular and raw strings. Understand why raw strings cannot end with an unescaped backslash, helping you write error-free string literals and improve your Python coding skills.

We'll cover the following...

Backslashes with strings can get tricky at times.

Python 3.5
print("\"")
print(r"\"")
Python 3.5
print(r"\")
Python 3.5
print(r'\'' == "\\'")

Explanation

  • In a usual python string, the backslash is used to escape
...