i am having difficulties with this Python regime I am developing to carry out maths, working out and also so solutions however I"m obtaining the syntaxerror: "unexpected character after line extension character in python"

this is mine code

print("Length between sides: "+str((length*length)*2.6)+" 1.5 = "+str(((length*length)*2.6)1.5)+" Units")My difficulty is through 1.5 I have actually tried 1.5 yet it doesn"t work

Using python 2.7.2



The backslash is the line extension character the error article is talking about, and also after it, only newline characters/whitespace are allowed (before the next non-whitespace proceeds the "interrupted" line.

You are watching: Python unexpected character after line continuation character

print "This is a an extremely long string that doesn"t fit" + "on a solitary line"Outside the a string, a backslash deserve to only show up in this way. Because that division, you desire a slash: /.

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

In her code, you"re utilizing it twice:

print("Length between sides: " + str((length*length)*2.6) + " 1.5 = " + # within a string; treated together literal str(((length*length)*2.6)1.5)+ # outside a string, treated together line cont # character, yet no newline follows -> failure " Units")


You need to press enter after continuation character

Note: room after continuation character leader 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">)


The department operator is / fairly than .

Also, the backslash has actually a special meaning inside a Python string. Either escape that with one more backslash:

"\ 1.5 = "`or usage a raw string

r" 1.5 = "


Well, what do you try to do? If you desire to usage division, usage "/" no "".If that is something else, define it in a bit much more detail, please.

As the others already mentioned: the department operator is / rather than **.If you wanna publish the ** character in ~ a string you need to escape it:

print("foo \")# will print: foo I think to publish the string you want I think girlfriend gonna need this code:

print("Length in between sides: " + str((length*length)*2.6) + " \ 1.5 = " + str(((length*length)*2.6)/1.5) + " Units")And this one is a more readable variation of the over (using the format method):

message = "Length in between sides: 0 \ 1.5 = 1 Units"val1 = (length * length) * 2.6val2 = ((length * length) * 2.6) / 1.5print(message.format(val1, val2))
many thanks for contributing response to ridge Overflow!

Please be certain to answer the question. Provide details and also share your research!

But avoid

Asking because that help, clarification, or responding to other answers.Making statements based upon opinion; back them up with references or personal experience.

See more: Número De Teléfono Consulado De Guatemala En Houston Texas, Consulado General De Guatemala, Houston, Texas

To learn more, watch our advice on writing great answers.

article Your prize Discard

By clicking “Post your Answer”, you agree to our regards to service, privacy policy and cookie policy

Not the price you're feather for? Browse other questions tagged python mathematics syntax continuation or asking your own question.

Bash in Jupyter Notebook: 'SyntaxError: unforeseen character ~ line continuation character'
site design / logo design © 2021 stack Exchange Inc; user contributions license is granted under cc by-sa. Rev2021.12.22.41046

your privacy

By clicking “Accept every cookies”, you agree ridge Exchange have the right to store cookie on your an equipment and disclose information in accordance v our Cookie Policy.