• Register
0 votes

Problem :

My Python program is giving below error
python unexpected character after line continuation character
6 5 3
6,930 points

Please log in or register to answer this question.

3 Answers

0 votes


Here backslash \ is the line continuation character the error message is talking about, and after it, only newline characters/whitespace are allowed

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

Further Readings:


9 7 4
38,600 points
0 votes

The backslash is the line continuous character, about the error message is talking and after it, only the new line characters and white spaces are allowed. Before the next non-whitespace continuous the “interrupted” line.

print “This is the very long sentence and does not seems to be fit “ \

           “on a single line”.

Multiple string literals:

If the multiple string literals are written sequentially, then they can be concatenated into one string like;

s = 'aaa' 'bbb'


# aaabbb

We can write the long string into multiple lines of code as follows;




# https://ja.wikipedia.org/wiki/%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0%E8%A8%80%E8%AA%9E

Strings surrounded by “”:

Only the string literals that are surrounded by ‘’ or “” can be concatenated if they are written consecutively. Note that in this case of variables error can occur;

 s_var = 'xxx'

# s = 'aaa' s_var 'bbb'

# SyntaxError: invalid syntax


Use the + operator to concatenate the variables, or the variables and string literals;

s = 'aaa' + s_var + 'bbb'


# aaaxxxbbb

You need to use the + operator to concatenate the variables, even if they are separated by a backslash (\).

s = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\

    + s_var\

    + 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'


# aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaxxxbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb


11 5 2
3,890 points
1 vote


Your issue is that you miss understood the syntax of strings, you did this:

'Text '\n'another text'

As you can see here, To write strings, you can use single quotes or double-quotes. And to add a new line:


What you did is that you ended the first string ‘Text ‘, then you put the newline character without strings quotes, then started a new string. Python’s syntax doesn’t work in this way, I know this is a bit of confusing, but take your time understanding it. 

      13 9 6
      94,240 points

      Related questions

      1 vote
      1 answer 43 views
      Problem: I was trying to run a simple python program but I am getting this error “syntaxerror: unexpected character after line continuation character” every time. What could be the reason and possible solution? print("Length between sides: "+str((length*length)*2.6)+" \ 1.5 = "+str(((length*length)*2.6)\1.5)+" Units")
      asked Mar 7, 2020 Gavin 15.3k points
      0 votes
      1 answer 196 views
      Problem : In Python, code blocks are defined by the tabs, not by the ";" at the end of the line if number > 10 and number < 25: print "1" Is mutliple lines possible in python? like... if number > 10 and number < 25: print "1"
      asked Oct 21, 2019 peterlaw 6.9k points
      0 votes
      1 answer 27 views
      On making a small program for math there returned an error "TypeError: 'NoneType' object is not subscriptable. Never before has been seen, this error, so no idea what it means. import math print("The format you should consider:") print str("value 1a")+str(" + ")+ ... /Nathan/Documents/Python/New thing", line 16, in <module> a = lista[1] - lista[0] TypeError: 'NoneType' object is not subscriptable
      asked Oct 24, 2020 psandprop 2.4k points
      0 votes
      1 answer 17 views
      Problem: Hello Kodlogs, I am a c language developer and recently wished to learn one more computer programming language to add more to my skill set. So, given priority to my thoughts, I jumped into learning Python programming. I am solving problems every day with Python. Anyway, I ... the new type of challenge do come in middle now I am facing the using of the argsort in python and how to use it.
      asked Jul 7, 2020 Gavin 15.3k points
      0 votes
      1 answer 25 views
      Problem: Hello all, I&rsquo;ve just completed learning basic python. I am come from the c language background, You may treat me as an intermediate-level python programmer though I know learning has no limit in the programming field. Recently, I started learning data analysis using ... I am a newbie in this field. I am trying to figure out the process of imshow( ) in dataframe using the matplotlib.
      asked Jul 6, 2020 Gavin 15.3k points
      1 vote
      1 answer 19 views
      Problem: Hello Kodlogs, I am a college student. I recently started learning computer programming using the Python programming language. I was solving some mathematical operations through Python programs. I&rsquo;ve stuck to solve a problem regarding square-root. In my program, I am ... an integer number? If you share the tip with me it would really help me a lot. Thanks for your kind concern.
      asked Jul 11, 2020 adamSw 11.3k points
      1 vote
      1 answer 16 views
      Problem: Hello all, I was solving algebra using the Python programming language, and I&rsquo;ve written some codes to make a Python program that supposed to calculate the value of 4^3 and print the value for the user. Here is my code snippet: n = 1 for i in range ... mind to execute the program. My queries to you, is there any simple way to evaluate the power value of an integer in Python? Thanks
      asked Jul 10, 2020 adamSw 11.3k points
      1 vote
      1 answer 62 views
      Problem: Hello Kodlogs, I am a high school student who loves computer programming. I&rsquo;ve got a minimal idea on Python programming language, hence I am writing codes using it for years. Today I was solving problems from my math textbook, and I&rsquo;ve thought ... domain error.&rdquo; My question is, why is the program&rsquo;s performance fluctuating? Could you please give me an idea? Thanks.
      asked Jul 6, 2020 adamSw 11.3k points
      1 vote
      1 answer 13 views
      Problem: Hello people, I was solving some mathematical problems from my textbook using a Python program. In a particular case, I needed to use an exponential operator to calculate the problem. I failed to write codes where I can achieve the exponential operator's behavior and ... in Python. So, I request you to keep your answer in simple words. Thanks again. I look forward to read your answers.
      asked Jun 29, 2020 adamSw 11.3k points