•

Check out our Community Blogs

Register and join over 40,000 other developers!

### Recent Blog Entries

• phi

I love this community !

# Multi-line statements

a+\ b+c

Best Answer dargueta, 03 November 2015 - 07:28 PM

You probably have trailing spaces after the backslash. The backslash must be the last character in the line, so anything after that--including spaces--will cause the syntax error.

Go to the full post

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

### #1 WolfganGt3

WolfganGt3

CC Lurker

• Just Joined
• 2 posts

Posted 01 November 2015 - 06:49 AM

I purchased the "Programming Python - OS Swift - Second Edition - Programming Guide for Beginners - Learn In a day!" based on reviews. I'm just doing this to learn something and I am a sort of electronics wannabe hobbyist. I prefer to have a book that I can reference because I don't like tabbing screens during programming. I started following the book to the end of chapter 4. With some minor difficulty, confusion  and experimentation I was able to complete all the provided examples. I am using Python 3.5 and programming in 'IDLE'.

At the end of chapter four, roughly the end. It is trying to explain the continuation character can be used to make a multi-line statement. This is the information that is provided:

a=10

b=5

c=5

sum= a+\

b+c

print sum

OUTPUT: 20

Without the continuation character \, I have successfully achieved my output of 20.

print ('a=10'); print ('b=5'); print ('c=5'); sum= a+b+c; print (sum) - This works

print ('a=10'); print ('b=5'); print ('c=5'); sum= a+\;    b+c; print (sum) - This does not work. I have tried many different things like putting it in parenthesis, or quotes, or adding the sum= variable to the b+c: sum= b+c, playing with double \\ etc...etc...etc..

I understand the book may be older than Python35's release. I am also using 4 spaces as the recommended indent.

SyntaxError: unexpected character after line continuation character - It says this for every version I try, even without the Semi-colon after the backslash.

My question is, How can I make that continuation character work?

Thanks,

Steve

.

Edited by WolfganGt3, 01 November 2015 - 06:50 AM.

### #2 dargueta

dargueta

I chown trolls.

• Moderator
• 4854 posts

Posted 03 November 2015 - 07:28 PM   Best Answer

You probably have trailing spaces after the backslash. The backslash must be the last character in the line, so anything after that--including spaces--will cause the syntax error.

sudo rm -rf / && echo \$'Sanitize your inputs!'

### #3 WolfganGt3

WolfganGt3

CC Lurker

• Just Joined
• 2 posts

Posted 03 November 2015 - 07:50 PM

Thank you dargueta! I was not even trying to hit the enter key after the backslash because my train of thought was, I still need to write the rest of the code.

I also noticed the only output required to equate to the book was just 'Output: 20'.

Here is the previous code:

print ('a=10'); print ('b=5'); print ('c=5'); sum= a+\;    b+c; print (sum)

Here is the functional code:

a=10; b=5; c=5; sum= a+\

b+c; print (sum)

Output = 20

Removed print commands, quotes and parenthesis on variables.

Removed all characters after the backslash and hit the 'enter'  key which allowed me to write on the next line and complete the math calculation.

Once again thanks!

### #4 dargueta

dargueta

I chown trolls.

• Moderator
• 4854 posts

Posted 03 November 2015 - 08:36 PM

No problem!

sudo rm -rf / && echo \$'Sanitize your inputs!'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download