close

[Solved] syntaxerror: unexpected character after line continuation character in python

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error syntaxerror: unexpected character after line continuation character in python in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How syntaxerror: unexpected character after line continuation character in python Error Occurs?

Today I get the following error syntaxerror: unexpected character after line continuation character in python in python.

How To Solve syntaxerror: unexpected character after line continuation character in python Error ?

  1. How To Solve syntaxerror: unexpected character after line continuation character in python Error ?

    To Solve syntaxerror: unexpected character after line continuation character in python Error Outside of a string, a backslash can only appear in this way. For division, you want a slash: /.

  2. syntaxerror: unexpected character after line continuation character in python

    To Solve syntaxerror: unexpected character after line continuation character in python Error Outside of a string, a backslash can only appear in this way. For division, you want a slash: /.

Solution 1

You must press enter after continuation character

Note: Space after continuation character leads to error

cost = {"apples": [3.5, 2.4, 2.3], "bananas": [1.2, 1.8]}

0.9 * average(cost["apples"]) + \ """enter here"""
0.1 * average(cost["bananas"])

Solution 2

The backslash \ is the line continuation character the error message is talking about, and after it, only newline characters/whitespace are allowed (before the next non-whitespace continues the “interrupted” line.

print "This is a very long string that doesn't fit" + \
      "on a single line"

Outside of a string, a backslash can only appear in this way. For division, you want a slash: /.

If you want to write a verbatim backslash in a string, escape it by doubling it: "\\"

In your code, you’re using it twice:

 print("Length between sides: " + str((length*length)*2.6) +
       " \ 1.5 = " +                   # inside a string; treated as literal
       str(((length*length)*2.6)\1.5)+ # outside a string, treated as line cont
                                       # character, but no newline follows -> Fail
       " Units")

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read