In the first you are escaping your closing ', hence the SyntaxError you mention in your question is raised, because your string now never terminates. In the second you are escaping the final \ so the ' is not escaped. '\\' is a literal backslash rather than an escape, which is why the ' is not escaped in the second version, and why the '\' at the end of the first version is not escaped.
To know more about this you can have a look at the following video tutorial:-