Python Forum
How to do line continuation in Jupyter Notebook?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to do line continuation in Jupyter Notebook?
#1
Hi all,

This:

#print('Date is {}, DTE is {}, EXP is {}, STRIKE is {}, PRICE is {}, VOL is {}, \
OI is {}, and DELTA is {}'.format(DATE, DTE, EXP, STRIKE, PRICE, VOL, OI, DELTA))


results in:

File "<ipython-input-70-20e6b91ee4d8>", line 2
OI is {}, and DELTA is {}'.format(DATE, DTE, EXP, STRIKE, PRICE, VOL, OI, DELTA))
^
SyntaxError: invalid syntax

It's one commented line with a backslash [trying] to indicate that what follows is a continuation of the same line.

What am I doing wrong with regard to the backslash?

Mark
Reply
#2
remove comment from line 1 and then indent line 2
Mark17 likes this post
Reply
#3
Unfortunately the continuation does not work for comments. You need to comment the second line also.
Mark17 likes this post
Reply
#4
(Sep-22-2021, 07:55 AM)ibreeden Wrote: Unfortunately the continuation does not work for comments. You need to comment the second line also.

Did not know that. Thanks.

For a regular line, after the backslash can I indent however I please or do I need to use four spaces?
Reply
#5
You are free to use the indentation you like on continuation lines. But good programmers do it according to PEP 8, which contains guidelines about formatting of code. Read the details in: Indentation.
In short: use at least the same indentation as the starting line or 4 spaces more. Or more spaces if it helps clarifying the coherence of the code.
Mark17 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Jupyter Notebook as IDE bytecrunch 0 465 Sep-12-2021, 07:41 PM
Last Post: bytecrunch
  How to programmatically stop a program in Jupyter Notebook? Mark17 10 3,868 Aug-27-2021, 11:53 AM
Last Post: jamesaarr
  [solved] unexpected character after line continuation character paul18fr 4 900 Jun-22-2021, 03:22 PM
Last Post: deanhystad
  It says there is no keras in jupyter notebook. it is wrong there is a keras install Led_Zeppelin 0 763 Apr-27-2021, 08:29 PM
Last Post: Led_Zeppelin
  importing matplotlib in jupyter notebook Led_Zeppelin 4 1,438 Feb-25-2021, 07:28 PM
Last Post: snippsat
  Jupyter Notebook cell ? flaviu2 5 1,564 Sep-29-2020, 11:06 AM
Last Post: flaviu2
  jupyter notebook varsh 0 908 Sep-25-2020, 08:56 AM
Last Post: varsh
  'utf-8' codec can't decode byte 0xe2 in position 122031: invalid continuation byte tienttt 12 4,672 Sep-18-2020, 10:10 PM
Last Post: tienttt
  how to install pyramid.arima in jupyter notebook bntayfur 1 1,815 Aug-06-2020, 04:37 AM
Last Post: ndc85430
  Help with pie chart in Jupyter notebook Rony28 0 717 Aug-01-2020, 06:03 PM
Last Post: Rony28

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020